I'm having some difficulty figuring out how the Aggregate Root will track changes on child entities.
Let say I have an aggregate:
With the Order
class being the aggregate root. How will I track the changes made on each of the OrderLineItem
through the Order
class?
When I make a repository (implementing) e.g. an OrderRepository
(because only the aggregate root can have the repository right?), how will my OrderRepository
track the changes of each OrderLineItem
?
Example:
How do you guys deal with this?
Advantages of domain-driven design The most obvious advantage of DDD is that it gets everybody using the same language. When development teams use the same language as domain experts, it leads to software design that makes sense to the end user.
Tactical DDD is when you define your domain models with more precision. The tactical patterns are applied within a single bounded context. In a microservices architecture, we are particularly interested in the entity and aggregate patterns.
In domain-driven design, an entity is a representation of an object in the domain. It is defined by its identity, rather than its attributes. It encapsulates the state of that object through its attributes, including the aggregation of other entities, and it defines any operations that might be performed on the entity.
with the Order class being the aggregate root now how will I track the changes made on each of the OrderLineItem through the Order class?
All changes to the Order
aggregate, including OrderLineItem
, should go through the aggregate root. This way, the aggregate can maintain its integrity. As far as tracking changes, that depends on your persistence implementation. If using an ORM such as EF or NHibernate, then the ORM will take care of tracking changes. If using event sourcing, then changes are tracked explicitly as a sequence of events, usually maintained by the aggregate in OOP implementations. If using SQL directly, you can also avoid tracking changes and update the entire aggregate upon each commit.
and when I make a repository(implementing) say OrderRepository because only the aggregate root can have the repository right?
Yes, repository per aggregate.
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