Domain-Driven Design – Why Aren’t Entities Allowed to Reference Other Entities Inside an Aggregate Except the Root?

Architecturedesigndomain-driven-designdomain-modelobject-oriented

I have read in several places this following rule concerning Aggregates:

Entities in one aggregate can hold references to any other Aggregate Root, but never to an
Entity or Value Object inside the other Aggregate.

What can go wrong if an Entity was holding a direct reference to an entity in another Aggregate root?

Can someone please explain why such rule is important? and preferably illustrate with an example, please?

Best Answer

The point of aggregate root is to encapsulate behavior of the whole through it's root. This simplifies the model, because you know any entity in aggregate will always be changed through only one entity, the root. By allowing entities to reference another entity, that is not a root in an aggregate, breaks this encapsulation.