For example, we have two domain objects: Cell and Body (as in human cell and body).
The Body class is just a collection of Cells, e.g.
class Body
{
IList<Cell> cells;
public void AddCell(Cell c) { ... }
public void RemoveCell(Cell c) { ... }
}
The Cell has a Split method, which internally creates a clone of itself, e.g.
Class Cell
{
public Cell Split()
{
Cell newCell = new Cell();
// Copy this cell's properties into the new cell.
return Cell;
}
}
Now, in DDD when the cell splits should:
- The cell add the newly created cell to the Body (which would mean that each Cell object held a reference to its containing body)?
- Or should the service layer which received the intitial user request call Split, collect the returned Cell and add it to the Body? (feels like a more anemic design using controllers rather than domain objects)
- Or should the Body contain a SplitCell method?
Thanks in advance.