I'm trying to improve my design using some DDD concepts. Currently I have 4 simple EF entites as shown in the following image:
There are multiple TaskTemplates
each of them storing multiple TasksItemTemplates
. The TaskItemTemplates
contains various information (description, images, default processing times).
Users can create new concrete Tasks
based on a TaskTemplate
. In the current implementation, this will also create a TaskItem
for every TaskItemTemplate
, but in the future it might be possible to select one some relevant TasksItemTemplates
.
I wonder how to model this requirement in DDD. The reference from TaskItem
to TaskTemplateItem
is not allowed, because TaskTemplateItem
is not an aggregate root. But without this reference it is not possible to get the properties of the TaskTemplateItem
.
Of course I could just drop the reference and copy all properties from TaskTemplateItem
to TaskItem
, but actually I like the possibility to update TaskItems
by updating the TaskTemplateItems
.
Update: Expected behaviour on Task(Item)Template updates
It should be possible to edit TaskTemplate
and TaskItemTemplate
and e.g. fix Typos in Name or Description. I expect these changes to be reflected in the Task/TaskItem
.
On the other hand, if the DefaultProcessingTime is modified, this should not change the persisted DueDate of a TaskItem.
In my current Implemenation it is not possible to add/remove TaskItemTemplates
to a persisted TaskTemplate
, but this would be a nice improvement. How would I implement something likes this? Add another entity TaskTemplateVersion
between TaskTemplate
and TaskItemTemplate
?
Update2: TaskItemTemplateId as ValueObject
After reading Vaughn's slides again, I think with a simple modification, my model is correct according to DDD:
Unfortunately I do not really understand, why this Design is better (is it better?). Okay, there won't be unnecessary db queries for TaskItemTemplates. But on the other side I almost ever need a TaskItemTemplate when working with a TaskItem and therefore everything gets more complicated. I cannot any longer do something like
public string Description
{
get { return this.taskItemTemplate.Description; }
}
TaskItems
when theirTaskItemTemplate
is modified ? – guillaume31