1

I am needing some assistance with designing with DDD.

I have three classes, Family, Child and event. Is the correct way to model this to to have Child in both Event and Family and make Family and Event an Aggregate Root.

My question is it ok to have an Entity as a member of two AggregateRoot?

    public class Child: Entity
    {
     ...properties and methods....
    }

    public class Family : AggregateRoot
    {
        private List<Child> _attendingChildren;

        public void NewChildInFamily(string firstName, string surname)
        {....create a new child and add it to attendingChildren....}
    }

    public class Event: AggregateRoot
    {
       private List<Child> _attendingChildren;

       public void NewChildAttending(Child attendingChild)
       { ....code to add existing child to attendingChildren....}
    }
1

No, this breaks the encapsulation of the aggregate, because Event is referencing Child, which is under other Aggregate root.

All 3 should be roots.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.