Domain Driven Design series: Entity and Value Object

 

As I have mention in the previous posting, DDD object can be modeling into Domain Object and Value Object.

The key defining characteristic of an Entity is that it has an Identity – it is unique within the system, and no other Entity, no matter how similar is the same Entity unless it has the same Identity.

Still don’t understand? Ok, think of house, is the house has identity? Off course it has. Is your house my house as well? No way!!! So the house can be treated as Entity class: it has identity, it is not sharable.

Im OK with the entity class concept, but is the value object the same with Value Object in the Java term…

It’s depend!!! In this DDD, the characteristic of Value Object is that it has no Identity. Ok, perhaps a little simplistic, but the intention of a Value Object is to represent something by it’s attributes only. Two VOs may have identical attributes, in which case they are identical. They don’t however have any value other than by virtue of their attributes.

Still blur…

Ok, the example is class paint. Let’s say our entity class want to use the class paint with  color attribute red. Let say, I am using that paint object to paint my house, and the remaining paint i pass to you to paint your house, so in this scenario, paint class is Value Object. It shareable. Let’s put the ID of the class paint, do you think the identification of the paint class is important? We do not need to take care the ownership of the class paint.

One more characteristic of Value Object is immutable, once created they cannot be changed or altered. You can create a new one, and as they have no identity, that is just the same as changing another one.

Ok, what should included in Domain Class anyway? Domain will contain all behavior. Just define any method that the object can do. Take the user domain object: what the user object can do? All getter and setter of all attribute. What else? We will go back to this again later in other post.

references:

Charlton, C.(2009). Domain Driven Design: Step by Step Guide
R.B.(2009).DDD Training Material

 

September 12, 2009 Post Under Domain Driven Design

Leave a Reply