应该珍惜的对象保持引用的实体? [英] Should value object hold reference to entity?
问题描述
应该珍惜在DDD方法的对象保持引用的实体?
Should value object hold reference to entity in DDD methodology?
修改
@Dmitry:
这可能是我的情况。在这里,我附上类图,其中帐户
坚持的 IInvoiceable
项集合引用。我对待租户
为实体,但只拥有一个账户,我不认为帐户
需要身份。其租户
的一部分。或者我应该把它当作实体?对我来说,它没有任何意义。
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.
推荐答案
是的,它可以。这将是一个相对模糊的情况下,但DDD允许它,它可能是有用的。从 DDD书Eric Evans的:
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:
值对象,甚至可以参考机构。例如,如果我问一个在线地图服务从旧金山到洛杉矶的一个风景秀丽的行驶路线,它可能会得出一个Route对象通过太平洋海岸公路连接洛杉矶和旧金山。这条路线的对象将是一种价值,即使它引用了三个对象(两个城市和公路)的所有实体。
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.
< A HREF =http://books.google.com/books?id=xColAAPGubgC&pg=PA98&lpg=PA98&dq=For%20example,%20if%20I%20ask%20an%20online%20map%20service%20for %20A%20scenic%20driving%20route%20from%20San%20Francisco%20to%20Los%20Angeles&安培;源= BL&安培; OTS = q9VzdhPL9o&安培; SIG = 7dWT-cJyutWo52Ad-LRWYGRrmUI和放大器; HL = EN&安培; SA = X&安培; EI = NndOT5KKIIjJiQLJvZyOCw&安培; VED = 0CDsQ6AEwAA#v = onepage&安培; q =为%20example,%20if%20I%20ask%20an%20online%20map%20service%20for%20A%20scenic%20driving%20route%20from%20San%20Francisco%20to%20Los%20Angeles&安培; F = FALSE>页#98
这篇关于应该珍惜的对象保持引用的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!