Domain-Driven Design – What Is a Value Object?

domain-driven-design

I have an entity and I've realised that there is a group of properties that work together. So, I moved them to a value object (together with their behavior) and now I have a reference from my entity to this value object.

I've read "Domain Driven Design Quickly" (PDF) and I came across the following statement when explaining Value objects:

If Customer is an entity object, then one instance of this object, representing a specific bank client, cannot be reused for account operations corresponding to other clients. The outcome is that such an instance has to be created for every client. This can result in system performance degradation when dealing with thousands of instances.

But I'm still not clear exactly what this means. Is my new object a value object or should it be an entity? I am having trouble reasoning whether it should in fact be an entity. In other words, what questions should I ask in my domain to assure me that it should be a value object?

Best Answer

To expand on the answer by ques, a value object does not have a surrogate identity such as a customer number, but the object itself is its own natural identity.

Take an address for example. All addresses are unique, and the various components of an address (number, street name etc) make up the addresses identity. When you move house, you don't pick up your address, change the number on the door and take it with you, you get a new address. As such value objects don't change - they are immutable. However you could have 2 or more customers living at the same address, in which case the address value is reusable - it is not tied to a single customer entity.

Related Topic