0
votes

I am confused about aggregate objects and that only aggregate objects have repositories because I don't know how to properly code it.

Assume that you have a User, Question and QuestionLog entity. I don't understand how to set the boundaries for how much you should put in an aggregate object. You could say that no questions would live in my system without a user, and a questionlog would not exist if it had no questions to be attached to. So would user be an aggregate root?

How would you add a questionlog then for instance?
For me it seems like you end up with a lot of nesting etc. User.addQuestionLog? I don't understand where the boundaries go for when it should be an aggregate and seen as a unit? For me it would be more natural that User is one aggregate and Question is another. However I don't understand how to actually know this.

And a question can have categories too, would the category also be a part of question or not? Why/why not? How to spot them?

1

1 Answers

2
votes

Don't think of the objects, DDD is all about real life.

The real questions are:

  • Can X exist whithout Y?
  • Is Y a part of X?

Hence:

  • Can a user exist without a question? Yes
  • Should the question still be available if the user quits? Yes
  • Is a log part of a user? No
  • Is a log part of a question? No (since it belongs to users, but is not part of a user)
  • Is a category part of a question? Typically yes

So we end up with three root aggregates.

The category is value object