Question

I've been struggling with modeling something out correctly, the DDD way.

The use case is quite simple. You're a User, and you can be part of a Group. So we have a 1 - many between group and users ( both are aggregates ).

Now, a user should know about it's users , so it contains a list with user ids ( I'm not putting a list of Users in their by purpose ).

But on the other hand, a User should also know in which group he is, so he should have a group id.

The problem here is that we have a bi directional association.

One way I can think to solve this is by not having a group id on the user, but retrieving the group containing the user id.

First of all is this an acceptable solution, if not, could you help me out working away that bi directional relationship ?

Thank you :)

Was it helpful?

Solution

Your initial approach is already leading you down a rabbit hole. You are trying to design a data-model instead of an object-model. The difference is the data-model models data and the object-model models behavior.

There is no "use-case" that a user needs to be a part of a group. The "use-case" is something the end-user does, like printing all groups on a web-ui, listing all users in a group on the web-ui, etc. Those are use-cases.

So I suggest you list all the behavior you need, try to assign them to either a User or a Group. After that you can add the data necessary for those behaviors to the objects.

Licensed under: CC-BY-SA with attribution
scroll top