AdamDev
AdamDev

Reputation: 335

Value Object within Value Object [DDD]

I'm having a little bit of difficulty trying to understand how to use Value Objects and Aggregates. I'm going to explain my situation with an example.

I have an entity called Relationship. It holds values such as ID and StartDate. There are two value objects: Boyfriend and Girlfriend. Both the boyfriend and girlfriend objects have addresses so I created another value object Address. Inside the database these are all combined in one table (i.e. ID, StartDate, BoyfriendAddress, GirlfirendState, etc.).

How do I create the Boyfriend and Girlfriend? From my understanding of the definition, they do not qualify as an aggregate because they do not have a root entity. Can a value object have another value object inside of it?

Upvotes: 6

Views: 3214

Answers (1)

Augusto
Augusto

Reputation: 29897

Yes, you can have value objects inside other value objects. I think the simplest example of this would be the class Money, which contains an amount and a Currency, which is another VO.

Also, if Boyfriend and Girlfriend don't have a global unique id, then they are not aggregate roots, and if they don't have a local unique identity inside a relationship, then they aren't entities either.

I'll be honest, 1st of all your app is not politically correct :) - As there are GLBT relationships. And 2nd, it feels strange that a person (I assume you have their names) is not an entity or aggregate-root.

Upvotes: 6

Related Questions