Should value object hold reference to entity?

丶灬走出姿态 提交于 2019-12-23 07:27:51

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/9498637/should-value-object-hold-reference-to-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!