tikhop
tikhop

Reputation: 2087

ddd: Entity or VO

Suppose I have a Passenger object that should contains Passport (government id) object. I am getting Passenger from PassengerRepository. PassengerRepository create request to server and obtain data (json) than parse received data and store inside repository.

I have confused because I want to store Passport as Entity and put it to PassportRepository but all information about password contains inside json than i received above.

I guess that I should use Passport as VO and put it inside Passenger (aggregate) object. Or I can create a PassengerService that will be include PassengerRepository and PassportRepository.

Any ideas?

Upvotes: 3

Views: 1307

Answers (2)

MikeSW
MikeSW

Reputation: 16378

I would say that the Passport is a VO. A person can replace her passport which means a new passport (new serial) is issued. I think the Passport is an entity only for the government as it needs to keep track of each unique entity. For the rest of us, we don't care if the new passport has the same id as the old one. We care about having a valid passport.

Upvotes: 0

Oded
Oded

Reputation: 499352

Value objects are objects that are defined by their attributes - two instances with the same attribute values are essentially the same value. If this is correct for your Passport type, then it should be a VO.

If it is indeed a VO, then you are sorted - it can only be accessed via the aggregate.

If, however, this is not the case and a passport, in your domain, has an identity that remains constant regardless of attribute changes (someone changes their name, for instance), then you need to think whether, in your domain do Passport entities only have meaning when attached to a Person or not. If they do only have meaning in this context, then they also should only be accessed via the aggregate.

Upvotes: 5

Related Questions