I am just starting out with the study of domain driven design and it is quite possible that my understanding of the Entities/Values divide is faulty so if this is so please let me know.
From my understanding, since its identity is completely defined by its properties an Address is the quintessential value object. From my understanding, this means among other things that there should not be a separate repository or data-access object for addresses.
This creates a dilemma for me since in my case an Address contains a Country where a Country has a name and a country-code and the list of country-codes is supposed to be loaded in from the database.
My question is, how do I design this? I want people to be able to create an address using the new operator but I don't want to create a data access object for country and if I do I certainly don't want to put a reference to it in the address object.
I have some ideas but I'd like to hear any suggestions anyone might have.
A value object can reference other entities. For example, in an application that generates a route that describes how to get from one point to another, that route would be a value object.
Value Objects can be especially useful as a means for describing concepts in an application that have intrinsic rules but which are not themselves entities. In many applications, some concepts that are described as entities would be better off implemented as value objects.
The main difference between entities and value objects lies in the way we compare their instances to each other. The concept of identifier equality refers to entities, whereas the concept of structural equality - to value objects. In other words, entities possess inherent identity while value objects don't.
there is nothing in DDD precluding value objects from holding references to entities. Therefore your address would have a reference to a country entity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With