0

I have a CategoryClass (Aggregate root) -> SubCategoryClass -> and now a relational entity (n-n).

Category (root) 1->N SubCategory 1->N SubCategorySlotType (n-n)

SlotType (root)

My SubCategory only exists in the context of the Category and the SubCategorySlotType only exists in the context of the SubCategory. Is this the right approach? How should my SubCategorySlotType be updated? Should the Category have methods to change/add them for the SubCategory and the CategoryRepository be responsible for the SubCategorySlotType?

enter image description here

Edit:

Can you e.g. have two sub categories with the same name under a category? All SubCategories Names are Unique (indenpendent of the Category)

2
  • The category contains a single sub category and the sub category contains a single slot type? Is this assumption correct? It's not quite clear from your description.
    – Andy
    Apr 2, 2019 at 6:44
  • What kind of limitations does the category impose on a sub category and a sub category on a slot type? Can you e.g. have two sub categories with the same name under a category?
    – Andy
    Apr 2, 2019 at 8:37

1 Answer 1

0

To help you decide which entities are AR candidates, you should look for invariants, i.e. consistence rules you must guarantee in your model. These rules may define things inside an Entity (like a Person must have a Name) or may define the relation between 2+ Entities. In this case you need to choose one Entity to be the entry point of changes that affect these related entities, the so called AR.

It's not clear what your invariats are, but let's say, for example, that Categories can exist without any SubCategory, but SubCategories must have at least one SubCategorySlotType, then Category would be AR for itself, and SubCategory would be AR for itself and for SubCategorySlotType so your code that adds a SubCategory will expect data for and add a corresponding SubCategorySlotType (so your invariant is respected).

3
  • Yeah Categories can exist without SubCategories (but are useless, since only subcategory is used for other tables) and the SubCategory requires at least 1 SlotType. So how would both Category and SubCategory be AR? The SubCategory is a direct dependent of the Category so shouldn't it be a child of the Category?
    – LoadIt
    Apr 3, 2019 at 7:33
  • Yes they can both be ARs. ARs are designed upon business rules and invariants, not parent/child relationships. If SubCategory cannot exist without a Category then SubCategory could (not necessarily) be your AR to encapsulate both Category and SlotType! Take a look at this nice article.
    – alexbrina
    Apr 3, 2019 at 10:40
  • I've read the article and at the moment I'm reading other posts in that blog (thank you btw, seems very detailed) So I'll put on old this question for now, and i'll come back after I finished reading all that. It seems that I was missing a big part of the DDD (it's a very hard topic to understand). And then I'll come back to clarify any doubts and close it.
    – LoadIt
    Apr 3, 2019 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.