Should the "user/developer" who wants to do something with an aggregate only be faced with the aggregate root? So should every method I want to call on an entity deep inside that aggregate be "routed" through the root? That would make the root having a very broad interface with a lot of boring code.
Or ist it allowed to traverse and navigate through the aggregate, picking the entity you want to deal with and invoke the method directly on it?
Or have I to ask the root to give me the entity (not allowed to traverse and navigate through the aggregate from the outside) and then call the method on this entity directly?
答案 0 :(得分:2)
指定为聚合的实体" root"是看门人,所以所有方法调用都需要先通过他。如果你考虑一下,这是有道理的。如果你分发一个内部实体,你如何确定它以预期的方式使用并且不变量被维护?此外,现在您的内部细节已经耦合,并且内部结构变化将在整个系统中波动。
请记住,我们会努力设计小型聚合体,因此如果表面积过大,可能会表明您的聚合边界是错误的。