Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD: solution for references to a non aggregate root

I have two aggregate roots and two non aggregate root entities:

entity relationships

I know, that the relation D -> B breaks DDD principle.

I heard, that in the most cases the solution is to make the referenced entity a new aggregate root.

But is making B to a new aggregate root really an option if B is a real child of A (B can not live without A)?

like image 577
frol Avatar asked Nov 15 '12 11:11

frol


1 Answers

I agree with you, sometimes it just doesn't make sense to separate one entity from its aggregate, because it fits so naturally in it. This is one of the reasons why I'm not totally sold on the "small aggregates" approach that some recommend.

In such a case, what you can do is get a reference to B by traversal of an instance of A instead of getting it directly. After all, if B can't exist without A, there's no reason objects outside of the aggregate should know about a particular B and not know about its A.

like image 121
guillaume31 Avatar answered Sep 19 '22 14:09

guillaume31