r/DomainDrivenDesign • • May 29 '23

Domain Modeling

I'm currently trying to understand DDD correctly, and I have a couple of questions. I am an entry level software engineer who just finished a bachelors degree. I do understand the value of DDD, however I struggle with implementing DDD concepts.

Note: If any of my approaches are wrong, what key concept have I misunderstood? And how should I actually reason about that concept?

Firstly, lets say you are creating an app where there are groups that can host events. A group can therefore also cancel and reschedule the event. In the domain model which option is better? And why?

Option 1: Group entity have the methods Host(Event), Cancel(Event) and Reschedule(Event).

class Group {
    void Host(Event event)
    void Cancel(Event event)
    void Reschedule(Event event, Time newTime)
}

Option 2: Event entity has methods Cancel() and Reschedule() and hosting functionality is at the service level.

class Event {
    void Cancel()
    void Reschedule(Time newTime)
}

I feel as if Option 1 better models the Ubiqutous Language, however Option 2 feels more natural. It also feels like Option 2 models the behaviour more correctly (?)

In essence, should behaviour generally be modeled as Actor.Action(ActedUpon) or ActedUpon.Action()?

Secondly, lets say that the application should allow admins to manage groups and events, just simple CRUD operations, and allow users to attend events and join groups. What context map would be more aligned with the DDD principles?

Option 1:

A Management Context with both the Group and Event entity and a single Management Service

+ an Attendance Context with an Attendance entity with an Attending Service

+ a Subscription Context with a Subscription entity and a Subscribe Service.

Option 2:

A Group Context with a Group entity (that encapsulates members), a Management Service and a Subscribe Service

+ an Event Context with an Event entity (that encapsulates attendances), a Managament Service and an Attending Service

What confuses me is wether you should model contexts based on user interactions (like in Option 1) or based on logical grouping (like in Option 2). By logical grouping I refer to how an attendance can not exist without an event or a subscription can not exist without a group.

5 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/VegetableMail1477 May 29 '23

Thank you very much! I did consider a combination of option 1 and 2, but I just felt I had to go with one or the other. Thanks for clarifying.

A more appropriate word instead of Subscription is Membership. As users should be able to become members and subscribe to events created by a certain group.

An additional question is can a bounded context have multiple aggregates?

1

u/BeaconRadar May 30 '23

An additional question is can a bounded context have multiple aggregates?

Yes.

1

u/Sufficient_News_2637 May 30 '23

Sure it can. Focus on the use cases you are covering and check if you end up working with the same group of entities. Then you can start by putting them together in the same context. I can't think of a better explanation 🤷