Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks Matt for replying. I am starting to understand what a value object is but my question was more to do with the paragraph I read in the pdf mentioned above. The paragraph talks mentions "cannot be reused for account operations" and "performance degradation". This is what confused me as I don't know what it is referring to. Can you help clear it up? –  JD01 Dec 19 '11 at 11:15
1  
The can not be reused part mens that you can not use one object for multiple purposes because each of them is an individual for itself. For each client in a bank you have to create his own account (you cant share this informations between more clients) the performance part means that if you have a lot of these "individuals" you are going to end up with a lot of them which first of all can fill up your memmory and secondly you will lose a lot of time for the creation of each of them. –  Ivan Crojach Karačić Dec 19 '11 at 11:36
    
@Ivan: Thank you. When I first read it I kept thinking about my data model and did I kept thinking of value objects as reference object (i.e not immutable) which is something I should not do in DDD. –  JD01 Dec 19 '11 at 12:43
add comment

The key property of a Value Object it that it has no identity. It is defined only by it's attributes, and any other instance with identical attribute values can be substituted.

Los Techies had a good explanation on their blog a while back, and it has been asked on StackOverflow.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.