26

Should value object hold reference to entity in DDD methodology?

EDIT

@Dmitry:

This is probably my case. Here I attach class diagram where the Account hold references to collection of IInvoiceable items. I treat with Tenant as entity, but it owns only 1 account and i dont think that Account needs identity. its part of Tenant. Or should I treat it as Entity? To me it doesnt make sense.

enter image description here

2 Answers 2

45

Yes it can. This would be a relatively obscure case but DDD allows for it and it can be useful. From the DDD book by Eric Evans:

VALUE OBJECTS can even reference ENTITIES. For example, if I ask an online map service for a scenic driving route from San Francisco to Los Angeles, it might derive a Route object linking L.A. and San Francisco via the Pacific Coast Highway. That Route object would be a VALUE, even though the three objects it references (two cities and a highway) are all ENTITIES.

page #98

Sign up to request clarification or add additional context in comments.

5 Comments

thanks, I edited my post, maybe that will reveal that I made somewhere mistake
It might be the case that you need to merge Tenant and Account into one Entity - TenanatAccount. Or you may have Tenant be Aggregate root and Account be an Entity inside the Aggregate root. Or your Account may still be a Value object - and hold references to other Entities. Its hard to give you an advice because we don't know enough about your domain. None of this approaches violates DDD, so choose one that makes you feel best right now and change it later, as your understanding of domain evolves.
thanks a lot. I probably merge them together because solo Tenant looks too anemic.
"Its hard to give you an advice because we don't know enough about your domain. None of this approaches violates DDD, so choose one that makes you feel best right now and change it later, as your understanding of domain evolves." - 10+ years later and still accurate.
for let say paginated result of some entity or aggregated root can we make one value object that wraps the aggregate root or list of entities with cursor (string) for example PaginedAudiiosList ( audios List<AudiAggregate> ,cursor String )
0

Take a look at this links, hope it will be helpful

http://lostechies.com/jimmybogard/2008/05/21/entities-value-objects-aggregates-and-roots/

http://domain-driven-design.3010926.n2.nabble.com/Entities-reference-another-Aggregate-or-point-to-another-Aggregate-td5840084.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.