Making Aggregates Work Together through Identity References

Prefer references to external Aggregates only by their globally unique identity, not by holding a direct object reference (or “pointer”). This is exemplified in Figure 10.6.

Image

Figure 10.6. The BacklogItem Aggregate, inferring associations outside its boundary with identities

We would refactor the source to

public class BacklogItem extends ConcurrencySafeEntity  {     ...     private ProductId productId;     ... }

Aggregates with inferred object references are thus automatically smaller because references are never eagerly loaded. The model can perform better ...

Get Implementing Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.