Contents
Is it correct for a root aggregate to hold a reference to an internal entity?
When following Domain-driven design (DDD), is it correct for a root aggregate to hold a reference to an internal entity that happens to be the root entity on a separate aggregate? Nothing outside the AGGREGATE boundary can hold a reference to anything inside, except to the root ENTITY.
Can a root object not be part of the aggregate?
Your aggregate root object should (generally) only have properties which are part of its domain. If you have an AR object with a property which is not in the aggregate then you are immediately faced with the question. ‘Why not?’
What are the dependencies between the DDD layers?
Dependencies between layers in DDD Dependencies in a DDD Service, the Application layer depends on Domain and Infrastructure, and Infrastructure depends on Domain, but Domain doesn’t depend on any layer. This layer design should be independent for each microservice.
How does DDD help you understand the complexity in the domain?
DDD patterns help you understand the complexity in the domain. For the domain model for each Bounded Context, you identify and define the entities, value objects, and aggregates that model your domain. You build and refine a domain model that is contained within a boundary that defines your context.
Which is better an entity or an aggregate?
I would rather have most of the behaviors tied to value objects rather than entities. One of the things I’d encourage is to keep entities free of behavior where possible, since identity is already a big burden to bear, and have behavior expressed in the value objects.
How are aggregates and entities used in Domain Driven Design?
A Purchase Order would probably need to have at least one Line Item to be valid. Here is a case of two or more objects that seem to belong together most of the time in terms of how you need to work with them. So treat PO as an aggregate of the PO entiity and the Line Item value objects. And make the PO entity the root of the aggregate.
Can a root entity hand reference to another entity?
The root ENTITY can hand references to the internal ENTITIES to other objects, but those objects can use them only transiently, and they may not hold on to the reference.
Can a entity be shared across many aggregates?
Since the premise of DDD is that the Aggregate is the entry point, you would be able to load A, modify entity E through it, all the while silently violating invariants from B (that you didn’t load). See the answer from Greg Young here : http://domain-driven-design.3010926.n2.nabble.com/Can-an-Entity-be-Shared-across-many-Aggregates-td7579277.html
What happens if entity E belongs to both aggregates?
Let’s say that entity instance E belongs to both aggregate instances A and B. Since the premise of DDD is that the Aggregate is the entry point, you would be able to load A, modify entity E through it, all the while silently violating invariants from B (that you didn’t load).
Can a root hand a value to another object?
The root may hand a copy of a VALUE OBJECT to another object, and it doesn’t matter what happens to it, because it’s just a VALUE and no longer will have any association with the AGGREGATE.