Complex root complexity in domain-driven design

Where do you draw the difficulty line of complexity? To clarify, if my aggregate has an ObjectA list that has an ObjectB list that has an ObjectC list, should my aggregate be responsible for retrieving the ObjectC? Or should I look at creating another aggregate so that this complexity is up to two levels in the hierarchy?

+4
source share
2 answers

In most cases, the boundaries of the Unit should be the boundaries of consistency needed for your model. This means that if changes to ObjectA or B or C need to be consistent with each other, they probably belong to the same aggregate.

Complexity (complexity of business logic) should be solved by defining all concepts in the domain and dividing the behavior into the entities / VO involved.

An object that receives complexity (infrastructure complexity) must be handled by the infrastructure, not the aggregate.

In the final model, you create the AR according to your domain and your boundaries of consistency, and not in order to facilitate the infrastructure.

+7
source

Like lulian, I think there are no rules that say what your AR should look like. If your AR with ObjectA, B, and C is in the same business context, that's fine. But I think you should also think about how your clients / use cases using your model. If you always want ObjectC and crawling an object from ObjectA and B to C to be perceived as an unnecessary crawl, then your model might be wrong.

If your root object is ObjectA, and you have an ObjectARepository, you can always add repository methods, such as GetObjectCsByObjectA (ObjectA objectA), which will display all C for A. If the ObjectC object can be a child of several ObjectB objects, which is the solution above, maybe is not the best since you get all C for one A.

Most importantly, how your GUI / clients will use this AR (repeat it yourself ...) You can add extension methods to add Linq filters or searches to make it easier to go from A to C. Not my favorite, but it works. It’s best to try to wrap the ObjectB collection in ObjectA with either a Value object or just a listwrapper class that is not saved and is created only when accessing this collection. This shell can provide the necessary access methods appropriate to your GUI, as well as checks when adding, replacing, and deleting list items. The wrapper will be a shortcut for your customers, so they don’t have to worry about how AR is created inside AR.

Does ObjectB and ObjectC have any associations with other objects outside this AR?

+1
source

All Articles