在以下模型中,地址不应该是值对象吗? [英] Shouldn't in the following model an Address be a Value Object?
问题描述
假定公司和个人都具有相同的邮件地址. 这些语句中的哪一个被认为是有效的?
Assume that a Company and Person both have the same mail Address. Which of these statements do consider valid?
1.如果我修改Company.Address,我希望Person.Address自动获得这些更改"
1."If I modify Company.Address, I want Person.Address to automatically get those changes"
2.如果我修改Company.Address,则不得影响Person.Address"
2."If I modify Company.Address, it must not affect Person.Address"
如果1为true,则地址应为实体
If 1 is true, Address should be an Entity
如果2为true,则Address应该是一个值对象.
If 2 is true, Address should be a Value Object.
在上述模型中,邮件Address
不应是 Value对象,因为即使Company
和Person
具有相同的邮件,该邮件也没有概念性身份?
Shouldn't in the above model the mail Address
be a Value Object, since even if Company
and Person
have same mail, this mail still doesn't have a conceptual identity?
换句话说,如果最初Company
和Person
共享 initial.address@gmail.com ,但随后又收到新邮件 new.address@gmail.com ,那么我们可以说邮件地址 initial.address@gmail.com 本身没有更改,而是Company
和Person
替换为 new.address@gmail.com 吗?
In other words, if initially Company
and Person
share initial.address@gmail.com, but then get new mail new.address@gmail.com, then we can argue that mail address initial.address@gmail.com itself didn't changed, instead Company
and Person
replaced it by new.address@gmail.com ?
据我所知,仅仅共享Address
的事实不足以赋予其个性(即身份)吗?!
Thus to my understanding a mere fact that Address
is shared shouldn't be enough to give it personality (ie identity)?!
谢谢
推荐答案
是的,您的理解是正确的. 地址几乎应该始终是一个值对象,因为在大多数域中,地址确实只是一个值.
Yes, your understanding is correct. Address should almost always be a value object, since in most domains, the address is indeed just a value.
今天 Company 和 Person 具有相同的 Address 的事实并不意味着如果一个改变,另一个也应该改变.如果存在这样的关系,则应通过显式约束对其进行建模,而不是通过使 Address 为实体.
The fact that a Company and a Person have the same Address today does not mean that if one changes, the other should change too. If such a relationship exists, it should be modeled through an explicit constraint rather than by making Address an entity.
埃里克·埃文斯(Eric Evans)在其,甚至提供了一个具体示例,其中 Address 可能是一个实体-邮政服务,其域围绕地址而行,而单个地址的身份很重要.
Eric Evans talks about this in his excellent book on Domain-Driven Design and even provides a specific example where Address might be an entity -- the postal service, whose domain revolves around addresses, and where the identity of individual addresses is important.
这篇关于在以下模型中,地址不应该是值对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!