I have a relatively simple domain model, as shown by the diagram. I would like to maintain this logic within my domain objects as defined by DDD.
Each domain object is an abstract class which only contains its respective members and domain logic. Concrete implementations of these classes are returned by the repositories, supplied to the service (with DI).
What I am having trouble with is understanding how to deal with the situation that I need to create a new entity. For example the domain logic dictates:
An account can be added to a Group
(creating a Member
entity).
When an account is added to a group, the new
Member
entity'sValue
property must be set to the total number of members that are already in theGroup
.Every other member of the Group must have their value incremented by 1.
I could implement this as a Member AddMember(Account account)
method on Group
. However this method will somehow need to instantiate a new Member
to add to the Group's Members collection.
As the domain object's have no references to the layers further up in the application, and the domain objects themselves are abstract, I'm unsure how to go about constructing the new instance of Member.
I have considered the possibility of defining an abstract protected Member CreateMember()
method on the Group
object that concrete implementations can implement but this seems messy to me and concerns me that I may be misunderstanding something more fundamental.
While trying to stay true to DDD principles, how would I go about implementing this model?