Enhancing descriptiveness with value objects
In the book Implementing Domain-Driven Design, the author Vernon Vaughn points out that we should use value objects to measure, quantify, or describe things from our problem domain. For example, you can describe an ID attribute with a value object instead of a long or integer value. You can wrap a double or big decimal attribute into a specific value object to express quantification more clearly.
We’re not fully satisfied with just using the built-in language types to model a problem domain. To make a system more explicit about its nature and purposes, we wrap those built-in language data types – and even our own created types – in well-defined value objects.
This effort to convey meaning is based on the following two fundamental characteristics of value objects:
- They are immutable
- They don’t have an identity
Suppose you have painted a picture. Imagine how strange would it be if, for some...