Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain driven design child entities change tracking

I'm having some difficulty figuring out how the Aggregate Root will track changes on child entities.

Let say I have an aggregate:

  • Order (root)
  • OrderLineItem

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:

  • Newly added but not committed to DB
  • Edited but committed to DB
  • Edited but not committed to DB

How do you guys deal with this?

like image 965
Patrick87 Avatar asked May 20 '13 19:05

Patrick87


People also ask

What are the advantages of domain-driven design in software development?

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.

What is tactical DDD?

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.

What is entity in domain-driven design?

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.


1 Answers

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.

like image 65
eulerfx Avatar answered Oct 20 '22 01:10

eulerfx