Reputation: 2721
Is it a best practice to update children of an aggregate root directly, or only through its aggregate root? For example, which is preferred:
Order.UpdateOrderLineQuantity(orderLine, quantity);
or
Order.OrderLines[0].UpdateQuantity(quantity);
Any guidance in this department would be appreciated.
Upvotes: 1
Views: 291
Reputation: 48675
An aggregate root is an object that encapsulates related child objects, so you should use the first technique.
In the same way that callers shouldn't care if Order IDs are stored as integers or byte arrays, they shouldn't care or know whether it uses OrderLines
or HideousLegacyObjects
to store and manipulate order details.
Upvotes: 2