Dabbling with domain driven design, I've run into a situation regarding how to identify aggregate roots within my domain model.
I have the following three classes, modelling a simple to-do list:
public class List {
private IList<Task> _tasks;
public List() { ... }
public string Name { get; set; } }
public IEnumerable<Task> Tasks() { ... }
public void AddTask(string descr) { ... }
public void RemoveTask(Task t) { ... }
public Task GetRandomTask() { ... }
}
public class Task {
private IList<Update> _updates;
public Task(string descr) { ... }
public string Description { get; }
public bool IsClosed { get; }
public IEnumerable<Update> Updates() { ... }
public void AddUpdate(string descr, bool close) { ... }
}
public class Update {
public Update(string descr) { ... }
public string Description { get; }
}
I can state the following about the model:
List, therefore, would seem to be the only aggregate root. (Indeed my data access layer will only allow load/save of List objects.) However I can't see how I can cleanly push the UI that currently exists on my Task class, on to the List class. At the moment my List class is handing out references to Task objects, allowing the caller to modify them.
Does this imply that Task is also an aggregate root, even if it's existence is dependent on a containing List?
Thanks in advance.
In my opinion you can have either 1 or 2 aggregate in this cases. It's all depends your task in the list will be large or not; as well as your update will be large or not.
If task or update will not grow a lot, one aggregate root(List)
will be fine.
Else you can separate them to two aggregate root(List, Task)
where List
can add Task
and Task
can add Update
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With