Is Aggregate Root with Deep Hierarchy appropriate in DDD?

后端 未结 2 1910
无人及你
无人及你 2021-01-02 19:46

I have a system where a user answers question in a form. I have objects representing this model but I am not quite sure how to organize these objects in terms of DDD.

2条回答
  •  时光说笑
    2021-01-02 20:13

    Even though an answer has been accepted I thought I may as well add my 2 cents:

    Deep hierarchies are (probably) fine but remember that the idea behind an aggregate is to actually prevent this. I tend to think of entities in an aggregate along the lines of:

    "Does this entity have any meaning without the AR?"

    Since I do not have any context w.r.t. your model I will use Order/OrderLine. Does an OrderLine have any meaning without the Order? Can I do anything (behaviour) with the order line by itself? The obvious answer here is "no".

    Each model will need to be treated based on the context. But ownership does not necessarily mean containment.

    These may be easier to see when you work with separate bounded contexts provided one gets the BCs correct :)

    In your case an Answer may have no meaning without its Question. But maybe a Question can live in a QuestionBank BC and a particular question may be used in both your Examination BC and your Enrollment BC. All these are totally made up so it would depend on your context.

    So if it is a case that Question can be an AR then the questions that are owned by your Form AR may simply be a Value Object or even a simple QuestionId.

提交回复
热议问题