In Domain Driven Design, when an object clones itself, which adds it to its container?

For example, we have two domain objects: Cell and Body (as in a human cell and body).

The Body class is just a collection of cells, for example

class Body
{
    IList<Cell> cells;
    public void AddCell(Cell c) { ... }
    public void RemoveCell(Cell c) { ... }
}

Cell has a Split method that creates its own clone, for example

Class Cell
{
    public Cell Split()
    {
        Cell newCell = new Cell();
        // Copy this cell properties into the new cell.
        return Cell;
    }
}

Now that DDD, when the cell is broken, should:

  • A cell adds a newly created cell to the Body (which would mean that each Cell object contained a link to its containing body)?
  • Or should the service level that received the Split user’s internal request request 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.

+5
5

Domain Driven Design (Evans) , service.

0

, splitCell() Cell. , , - , , , . .

+2

- , , " " - . - , .

, Split Cell? - ? Split (Void) , ?

+2

DDD . - , , - , , SplitCell Body.

, , , , . Regenerate - Body, , Split .

, ...

+1

Cell , #.

, Cells , , - .

, Body, . (, ORM) .

A simpler alternative is to keep the link to the parent Body(the cells belong to only one Body, right?), And let the new one Celladd to it Body.

  • Pros: easy to code, debug, understand.
  • Cons: Cell and Body become closely related, which makes them more difficult to reuse in other contexts (which may be irrelevant).
+1
source

All Articles