Let's assume a project presenting those specifications:
- Each
Employee
can organize aMeeting
inviting otherEmployee
s. - Each
Employee
can accept the invitation to participate to theMeeting
, while the number of maxParticipation
s isn't exceeded. - Any
Manager
of theEmployee
creator can cancel theMeeting
at any time.
IMO, the invariants are:
- A Meeting
exists
as long as the creator (Employee
) exists (not deleted or flag as deleted). - There shouldn't be at any time a
Meeting
containing a number of participants superior to the limite intended. - Any
Employee
that cancels its createdMeeting
should have also thisParticipation
s canceled /deleted. - When a
Manager
cancels anEmployee
'sMeeting
, both theMeeting
and theParticipation
s should be deleted.
Should I make:
- the
Employee
an Aggregate Root, containing the collection of its createdMeeting
s. Meeting
being thus an inner entity ofEmployee
and containing a collection ofParticipation
s.- Manager as the other Aggregate Root, containing a collection of its
Employee
s.
Thus there would be just to Aggregate Roots:
Employee
and Manager
.
Indeed, a Manager could be fired and then is not part of an invariant with the Employee
, and vice versa.
In details:
_ Employee
would provide a method createParticipation
, encapsulating checks for the important rules like whether the number max of participants is exceeded.
_ Employee
would provide also a Factory to create Meeting
, allowing to always assign the correct EmployeeId
to the Meeting
.
_ Only two repositories would be created: EmployeeRepository
and ManagerRepository
, avoiding direct access to respective inner parts.
(that deals only with creations, deletions would be similar)
Therefore, in order to create a Meeting
's Participation
, my entry point would be the creator(Employee
) that I retrieve through the EmployeeRepository
.
Does it make sense in order to follow strict DDD practice?