The above is this The model in the book. The customer is also the aggregate root.
With this model, there may be cases where the engine can have height, width and length attributes.
What happens when you need to install a large engine on a small car? The engine cannot adapt.
If the car checks the engine properties and allows it or not to be part of the car, is this a problem?
Engines have a global identification (like you know that every engine has a serial number/manufacturer number). Maybe the engine needs to be tracked by the manufacturer.
So I ask again, if the car uses an engine The attributes of it are loaded inside (allow it or not part of it), is this a problem?
Is it a problem if the car checks for the engine attributes and allows it or not to be a part of the car?
No.
That being said, your verification may be complex enough to introduce domain services. Two aggregations, you can do this:
car.Fit(engine)
or this:
< pre>engine.Fit(car)
However, you may want to check the car model:)
Since the rules will be more advanced and involve some data, you may want to introduce a domain service And it is possible to use double scheduling on the object:
So, instead of car.Fit (engine), you can do this:
car.Fit(engine , IModelServiceImplementation)
and in the Fit method call:
if (!IModelServiceImplementation.CanFit(car, engine)) {throw new Exception(); }
The service may load the correct model instead of checking the engine. Depending on the domain, there may even be modification levels and other rules to handle.
Because the Car instance does not contain the actual Engine Instance, and only contains EngineId or may contain a certain value object, so the engine will not really be assigned to the car. You can still pass the engine instance to the car and let it create an association, but it considers it appropriate.
The solution proposed by’Enrico S.’ may be more relevant to the case of making changes to the aggregate root, where there may not be all aggregate roots available, or even the aggregate root exists in a separate bounded context. Even if the car and engine are located in different In the BC, it may be possible to query the validity in some way. Some things can be used for final consistency, but others may not.
As usual, there are many things to consider:)
I am reading a book about DDD and I see a Example domains for cars, engines, wheels, and tires.
The above is the model in this book. Customers are also aggregate roots.
With this model, there may be engines that can have height, width, and In the case of length attributes.
What happens when you need to install a large engine on a small car? The engine cannot adapt.
If the car checks the engine properties and allows it or not to be part of the car, is this a problem?
Engines have a global identification (like you know that every engine has a serial number/manufacturer number). Maybe the engine needs to be tracked by the manufacturer.
So I ask again, if the car uses an engine The attributes of it are loaded inside (allow it or not part of it), is this a problem?
Is it a problem if the car checks for the engine attributes and allows it or not to be a part of the car?< /p>
No.
That being said, your verification may be complex enough to introduce domain services. Since there are two aggregations involved, you can do this:
car.Fit(engine)
Or this:
engine.Fit(car)
However, you may want to check the car model:)
Since the rules will be more advanced and involve some data, you may want to introduce domain services and may use double scheduling on the object:
So, instead of car.Fit (engine), you can do this:
car.Fit(engine, IModelServiceImplementation)
In the Fit method call:
if (!IModelServiceImplementation.CanFit(car, engine)) {throw new Exception(); }
The service may be loaded The correct model, rather than checking the engine. Depending on the domain, there may even be modification levels and other rules to deal with.
Since the Car instance does not contain the actual Engine instance, it only contains the EngineId or may contain a certain value Object, so the engine is not really assigned to the car. You can still pass the engine instance to the car and let it create an association, but it thinks it is appropriate.
The solution proposed by’Enrico S.’ may be related to The case of making changes to the aggregate roots is more relevant, where not all aggregate roots may be available, or even aggregate roots exist in a separate bounded context. Even if the car and engine are in different BCs, it may be able to query in some way to be effective Sex. Some things can be used for final consistency, but others may not.
As usual, there are many things to consider:)