Replies: 2 comments
-
An entity is owned by one aggregate root, as otherwise, the aggregate cannot fulfil its constraining nature. That's is why you declaration of From what you write, it feels like Bar should be its own aggregate and |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response! I adjusted Is there a reason that this restriction is in place, if I may ask? I read the blue book and partially the red book and can't remember that it was stated there that it's not recommended to have more than two levels of entities within one Aggregate (including the Aggregate Root). The red book gives an example of an Aggregate which consists of three levels of Entities at page 356 (figure 10.3). Admittedly, it is given as an example for a large-cluster Aggregate which won't scale well, but it's not said that this shouldn't be possible in general; it's only stated that an Aggregate should be as small as necessary. To give a more concrete example: I'm modelling a Scrabble-like board game. The Game Bounded Context comprises game logic only. Here, a Game consists of Players and a Board. A Board consists of multiple Rows. A Row consists of multiple Fields on which Tokens can be placed. Each Player has a set of Tokens. I thought of Game to be an Aggregate Root, because its placeTokenOnBoard(...) -method/interface ensures that a player can only place Tokens on the Board which they are in posession of. I thought of Board, Row and Field to be Entities because they all have a lifecycle throughout the Game (Tokens can be placed on them). I was thinking that it doesn't make much sense for Board to be its own aggregate that is referred to from Game by its identifier or an |
Beta Was this translation helpful? Give feedback.
-
I tried to model a domain using jmolecules and trying to nest multiple Entities resp. AggregateRoots lead me to compilation errors:
Entities example:
For (1) I get:
AggregateRoots example:
For (2) I get:
I am wondering if I am doing something wrong in this regard, if this kind of modelling is something which is not allowed / recommended in DDD and hasn't been implemented because of that or if this is maybe something which could be implemented in the future?
If I'm not mistaken the AggregateRoots example could work if Foo referred to Bar by Bar's ID; in this way Bar wouldn't be part of the Foo Aggregate. However, it feels to me that in the Bounded Context I am modelling it doesn't make a lot of sense for Bar to be able to exist without Foo, so I went for the approach shown here (Foo having a direct reference to Bar). I'm happy to share a bit more about the domain I am modelling if this is helpful.
Beta Was this translation helpful? Give feedback.
All reactions