Aggregates

An aggregate is a collection if entity and value objects that represents a domain object together with its components and properties.

Letting clients access the components of an aggregate is risky. All access should be through a designated root object. (Usually this will represent the aggregate itself.)

Aggregates need to stay together. Saving, reading, deleting, or archiving the root of an aggregate saves, reads, deletes, or archives all of its components.

In the example below the components are only used to communicate with customers through root methods:

UML allows us to represent the relationship between aggregates and their components using the diamond notation on the aggregate's endpoint.

In UML we can distinguish between shared aggregation (hollow diamond—components may be shared between aggregates) and owned aggregation (aka composition, solid diamond—components are not to be shared.)

For example, if customers can share addresses we could model this as:

We try to avoid sharing inside of an aggregation. For this reason I have moved the Address class outside of the aggregation boundary.