在 DDD 方法中,值对象是否应该持有对实体的引用?
编辑
@德米特里:
这可能是我的情况。在这里,我附上了类图,其中 Account
包含对 IInvoiceable
项目集合的引用。我将 Tenant
视为实体,但它只拥有 1 个帐户,我认为 Account
不需要身份。它是 Tenant
的一部分。还是我应该将其视为实体?对我来说这没有意义。
最佳答案
是的,可以。这将是一个相对模糊的案例,但 DDD 允许它并且它可能很有用。来自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.
关于c# - 值对象是否应该持有对实体的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9498637/