DDD - Share or duplicate a value object to be used between two aggregate roots?
Asked Answered
P

1

6

If I have a payment value object can it be shared by two different aggregate roots? or should I duplicate it?

Both options feel wrong!

Portal answered 27/11, 2014 at 2:3 Comment(9)
Is the answer in this post suggesting it is ok to share #7478179?Portal
Why do they feel wrong? A value object represents a value of a business concepts as defined by the language of the bounded context.Clearing
Actually it's only the duplication that feels wrong. Sharing it feels right... but what is Eric referring to when he says: "Nothing outside the Aggregate boundary can hold a reference to anything inside except to the root Entity"?Portal
It means that anyone using the aggregate must do it via the aggregate root. In short, only the aggregate root is 'usable' directly.Clearing
That's what I thought. So a Value object in AR1 should not be accessible by AR2. The problem is the value object in AR1 makes perfect sense in AR2 as well... now I am starting to think the two aggregate roots belong in different BCs.Portal
No, a value object is just a value, the 'reference' is for entities. It doesn't matter that the implementation of a value object is a class, the DDD reference has nothing to do with an object reference from OOP. DDD doesn't care what programming language you're using.Clearing
right... so you're saying the same value object can be used inside different aggregates?Portal
@user2909756 Yes, VO types can can be shared by any number of Aggregates in the same BC.Joaquin
The whole point of VOs being immutable is that they can be shared between various ARs/entities/clients without being afraid of side effects.Murmurous
C
7

As long as your VO is immutable, you can share it without any issues. However, Evans prohibits sharing mutable VOs and I think you will also agree with that.

Callery answered 27/11, 2014 at 17:23 Comment(1)
That makes perfect sense. Thank you for the clarification :)Portal

© 2022 - 2024 — McMap. All rights reserved.