To distinguish whether an address is an object of value or essence, ask yourself the question - if a person changes the address and the 2nd person has the same address, will both change? If they both change, the address gets promoted to the entity (the reason is the identity of the address, not the value).
To distinguish whether an address is an entity or an aggregated root, ask yourself the question - does the address really make any sense on it or is it always attached to a person, is it modified, deleted with it? If it is not connected with the person, but exists on it own (in the model you are modeling, not reality), then the address is the aggregate root.
Strictly speaking, this aggregate root is not needed, but if I do not have it, I will need to cross many objects in order to get the full address. Does it make sense to create a composite root based on this argument?
No no. Technical questions should not be associated with your domain. An entity can act as a “sub-aggregate," an address can contain a municipality, a city, etc. And still be just an entity (because it doesn’t make sense without a person).
In this case, the person will never refer to anything other than the aggregate root, however, only the municipalities can display the user interface (when viewing addresses, etc.). Is this a violation of the general idea of the root?
The presentation should also not conflict with your domain. As far as I can see, this is great if you show only the list of entities and hide the aggregated elements to which they belong.
Two people can be associated with the same address, and if one of them moves the other, it does not move automatically.
Question: how do you want to simulate this movement process?
I see two ways:
- When person # 1 moves, the address is changed , but the address of person # 2 does not match the address and therefore is not affected. In this case, the address is just an object.
- When person # 1 moves, move the switch to another. In this case, the address is the cumulative root.
Addresses exist on their own, and if a person moves to an address, he will be associated with him.
This means that you want to stick to the 2nd method (when the address is an aggregated root). This is normal and there is nothing wrong, but you have to check if the address can go down to the entity level, which will make your domain model less complicated.
And keep in mind - there is no "Model", there is only a "Model". You cannot simulate reality to accurately simulate it. You can model only part of it to solve specific problems .
This is why it is so difficult to answer questions related to ddd. No one knows your problems that you are trying to solve.
If I understand correctly ( http://msdn.microsoft.com/en-us/magazine/dd419654.aspx - part about aggregates), then whether the address can exist without a person (or another addressee) does not matter; the question is whether component addresses can exist or be available without an address. If they can, the address should not be an aggregated root.
This is relevant. If the address cannot exist without a person (which does not apply here) - it will inevitably be demoted as an object (because it does not make sense without a person) or an object of value (if the address itself does not have an identifier). Otherwise, you enter the unnecessary aggregated root.
It is good if the aggregate root contains references to other aggregate roots (but not the entities of other roots of the aggregate). Thus, addressable components can also be aggregate roots (the municipality referenced in PostOffice), and this will not change if the address itself is an entity or aggregate root.