Domain Driven Design – Aggregate Relationships Explained

aggregatedomain-driven-design

I have a question related to relationships between aggregates in Domain Driven Design.

I have the following situation: I have an aggregate (questionnaire) which has some children (questions). The questions are entities, but because they are inside the questionnaire aggregate they can have local identities (i.e. question with id 1 in questionnaire with id 1234; I can have another question with id 1 but in another questionnaire). So to refer to a question you always have to qualify it with its parent questionnaire id.

On the other side I have another aggregate (collection campaign) which stores data (response set) for the questions in a questionnaire (the collection campaign points to the questionnaire by its id, and a response set points to a question again by its id). I can have several collection campaigns (which took place at different times perhaps) and each collection campaign stores different response sets, but for the same questionnaire (and questions).

So my question is: have I designed this well (according to DDD)? Or do I have to keep the questionnaire and questions as separate aggregates of themselves in order to refer to them from the collection campaign/response sets?

I hope this makes sense and thank you.

Best Answer

I think this is fine, though you should consider the campaign to member the same aggregate. Otherwise if you delete a questionnaire the campaign gets orphaned. A campaign can't live on without it's questionnaire. Also using the local question ids would be a cleaner fit if it members the same aggregate.