Entities and Value Objects
Entities and Value Objects (VO) form the core building blocks of Domain Driven applications. Why has it taken this long to get to something so fundamental? Back in the good old days we used to have things called business objects, these were classes that held some data, had some methods, and we threw into a database.
DDD has refined this concept a little, by splitting the idea of these business objects into two distinct types,Entities and Value Objects
Entities
“this is my Entity, there are many like it, but this one is mine”
Whichever way you choose to represent it, an Entity is defined by having an Identity.
Value Objects
The key defining characteristic of a Value Objects 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.
Another aspect common to VOs is that they should probably be 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.Examples of common Value Objects: Money, Address, ProductCode