The value objects are simple but very useful objects. Value object, one of the powerful concept from DDD, is an object that describes a characteristic of a thing.
According Eric Evans,
An object that represents a descriptive aspect of the domain with no conceptual identity is called a value object. Value objects are instantiated to represent elements of the design that we care about only for what they are, not who or which they are. [Evans 2003]
Here a few characteristics of value object:
- The key defining characteristic of a value object is that it has no identity. In other words, the intention of a value object is to represent a concept by it’s attributes only.
- They should probably be immutable, once created they cannot be changed or altered.
- They are not DTOs, not Java beans and not objects with public fields, they encapsulate data with some behavior. DTOs are bunch of data, which are not necessarily coherent, VOs contains high-chorent data with behavior. The purpose of DTOs is data transfer but the purpose of the VOs is domain representation.
- They are mostly very simple objects.
- They “swallow computational complexity”.
- More extensible
- More testable
Some examples of value objects are money, addresss, phone number, product code, email address, etc..