Defining value objects
As we have already seen in Chapter 2, Wrapping Business Rules inside Domain Hexagon, entities are the elements we use to classify system components that have an identity. Conversely, the value objects don’t have an identity. We use value objects to describe those system parts where there is no need to define an identity. Then, we have aggregates that serve to encapsulate the objects’ related entities and values.
I recommend starting by creating value objects first because they are like the building blocks, the raw material we’ll use to build more elaborate value objects, and – most importantly – the entities. Now, we’ll add all the volume object classes on the Domain hexagon module, which were created in the previous section when we bootstrapped the Domain hexagon. We’ll use the following steps to define the value objects:
- Let’s start with the
Id
value object class, as follows:package dev.davivieira...