Assuring consistency with aggregates
We've so far seen how valuable entities are to represent things in a problem domain. Also, we saw how value objects are essential to enhance the descriptiveness of the model we are modeling. But how to proceed when we have a group of related entities and value objects that express a whole concept when put together? For such a scenario, we should employ the use of aggregates. The idea is that objects inside an aggregate operate in a consistent and isolated manner. To achieve such consistency, we must ensure that any change on any aggregate object is conditioned to the variants imposed by such an aggregate.
Aggregates are like an orchestrator that orchestrates data and behavior on the objects it controls. For this approach to work, we need to define an entry point to interact with the aggregate realm. This entry point is also known as the aggregate root, which keeps references to the entities and value objects that are part of the aggregate...