I have a question regarding handling multiple levels of nesting of child entities within an aggregate root.
Up until now I have only been dealing with aggregates roots with no children, or at most "one level" of nested entities.
When creating and modifying the child, I've managed that through the AR ie. Using traditional Order / OrderLines example:
class Order:
public void addOrderLine(product, price)
public void adjustPriceForOrderLine(percentage_change, line_id)
I've just designed an AR with 2 levels of nesting(both 1-to-many), and am having a hard time determining an approach for handling interactions through the AR:
class Root:
public void addLevelOneChild(...)
public void adjustLevelOneChild(...)
but when it comes to working with the child nested beneath the LevelOne child, the approach I've been taking becomes more verbose.
public void addLevelTwoChildToLevelOneChild(..., levelOneChild_id)
public void adjustLevelTwoChildInLevelOneChild(..., levelOneChild_id)
It works. But always requires effort to determine the local identifier of the Level One child before any action can be taken on the Level Two Child.
Also, when creating a new levelOneChild with a factory method, I need to either return the local id for the levelOneChild to then create a levelTwoChild, or jump through some hoops to get the local identify of the new levelOneChild.
public local_id root.addLevelOneChild(...)
public root.addLevelTwoChildtoLevelOneChild(..., local_id)
or
public void root.addLevelOneChild(...)
public local_id getIdforLevelOneChild(some natural identifier(s))
public root.addLevelTwoChildtoLevelOneChild(..., local_id)
Does this seem like the right approach? Or any suggestions for a more elegant solution.
I have been thinking of using natural IDs (I'm currently using a guid just for consistency) for local_id, which would help alleviate the need to return or query the generated key. Although this is letting persistence implementation details leak out.
Thanks