Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD Aggregates and value objects

I'd like to ask question about DDD features. Lets say we have two aggregates and each of them contains value-object Address. Accordingly to Eric Evans DDD, we should isolate aggregates from each other, so aggregate root of first aggregate can't have a link to Address. Frankly, it doesn't seem to make sense for me, so question is how to resolve such situation? Which aggregate should contain Address?

Thanks

like image 861
madcyree Avatar asked Sep 19 '11 21:09

madcyree


People also ask

What is a DDD value object?

Value Object is an object that represents a concept from your problem Domain. It is important in DDD that Value Objects support and enrich Ubiquitous Language of your Domain. They are not just primitives that represent some values - they are domain citizens that model behaviour of your application.

What is an aggregate object DDD?

A DDD aggregate is a cluster of domain objects that can be treated as a single unit. An example may be an order and its line-items, these will be separate objects, but it's useful to treat the order (together with its line items) as a single aggregate.

Can a value object be an aggregate root?

Thus, the aggregate root must be an entity, not a value object, so that it can be persisted to and from a data store using its ID.

What is the difference between entity and value object in DDD?

The main difference between entities and value objects lies in the way we compare their instances to each other. The concept of identifier equality refers to entities, whereas the concept of structural equality - to value objects. In other words, entities possess inherent identity while value objects don't.


1 Answers

You could have it using the same value object. But only do this if the aggregate roots exist in the same bounded context and hence has the same meaning for both aggregates. If the aggregates exist in different bounded contexts, then have 2 separate ones and duplicate. Leaking one bounded context's concerns into another is what Eric is trying to fight.

To most, the concerns of entity vs. value object boil down to people having issues with duplication of data. We have been so trained to think in 3rd normal form of a single canonical model. DDD fights the inevitable complexity that that brings by forcing duplication where it's needed and allowing concepts that were once thought to be one into many.

Hope this helps

like image 188
Adam Dymitruk Avatar answered Sep 24 '22 08:09

Adam Dymitruk