评论历史应该是一个实体,DDD
我目前正在使用 DDD 方法设计一个 Web 应用程序。在区分实体和值对象时,我遇到了一个这样的模型元素,我无法决定将其放置在实体/VO 类别下。
每个订单将与 1 个且仅 1 个管理评论列表的评论历史对象相关联。现在,当编辑订单时,用户可以添加评论。这会附加到评论历史记录中。
Comment History 对象本身在持久性方面没有任何意义。我计划使用 nHibernate“组件”,以便有效地仅将注释列表写入 ORDER_COMMENTS 表中。
订单是一个实体。
评论历史记录(附加到订单中的各种用户评论)应该是实体还是 VO?
I'm currently designing a web application using DDD methodology. While distinguishing the Entities from value objects, I came across one such model element which I'm unable to decide to place under Entity /VO category.
Every Order will be associated with 1 and only 1 Comment History object which manages the List of Comments. Now when the order is edited, a user may add a comment. This gets appended to the comment history.
Comment History object as such doesn't mean anything when it comes to persistance. I'm planning to use nHibernate "component" so effectively only the list of comments gets written down to ORDER_COMMENTS table.
Order is an Entity.
Should Comment History (Various user's comments appended to the Order) be an Entity or VO?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CommentHistory 是一个实体。
因为您会在其中添加注释,而不是每次更改时都替换整个历史记录。
这意味着 - 它是可以修改的。
如果它是可修改的,它必须有一个身份,一个已知的“挂钩”,您可以“悬挂”状态更改。
如果它具有独立于状态的身份,则它是一个实体:
相反,值对象是通过它们的状态来识别的。如果它们是通过状态来标识的,那么,如果状态发生变化,它就已经是一个不同的对象了。物体改变自身身份的能力过于自由,最终会导致混乱。由此得出的结论是,值对象应该是不可变的(它们的状态在每次构造时仅定义一次)。
这是另一个例子:
假设
Citizen
就像评论。公民被“附加”到国家/地区
。如果国家是一个价值对象,那么每当新公民诞生时,整个国家就需要重建。CommentHistory is an entity.
Because You append comments to it instead of replacing whole history every time it changes.
That means - it's modifiable.
If it's modifiable, it must have an identity, a known "peg" on which You "hang" state changes.
If it has an identity which is independent from state, it's an entity:
In contrast - value objects are identified by their state. If they are identified by state, then, if state changes, it's a different object already. Ability for objects to change their own identity would be too much freedom which eventually would lead into chaos. That leads to conclusion that value objects should be immutable (their state is defined only once, per construction).
Here's another example:
Assume
Citizen
is like comment. Citizens are "appended" toCountry
. If country was a value object, every time new citizen born, whole country would be needed to be reconstructed.从我的角度来看,我将评论历史视为价值对象,我的意思是,评论历史只是给定时间的评论的集合。尽管您每次添加评论时都可以重建或不重建评论历史记录,但它没有自己的身份和生命周期。
我的意思是,如果您必须使用相同的评论来评论历史记录,我们是否有两个不同的评论历史记录?我不这么认为,我们有相同的评论历史,我们不关心身份,我们关心的属性,即评论历史里面的评论要一样。
所以对我来说评论历史是一个VO
谢谢
巴勃罗
From my point of view I see the comment history as the value object, I mean, a comment history is just a collection of comments at a given time. despite the fact that you can reconstruct or not the comment history every time you add an comment to it, it does not have an identity and lifecicle of its own.
I mean if you have to comment histories with the same comments do we have two different comment histories? I do not think so, we have the same comment history, we do not care about the identity we care about the attributes, i.e. the comments inside the comment history to be the same.
So that for me the comment history is a V.O.
Thanks
Pablo
出于上述所有原因,注释是一种值类型。
CommentHistory 是 Order 的属性,不需要单独的对象。它只是 Comment 值的集合。 Order 在内部维护集合并通过 AddComment 方法控制访问。
Comment is a value type for all the reasons described above.
CommentHistory is a property of the Order and does not require a separate object. It is simply a collection of Comment values. The Order maintains the collection internally and controls access through an AddComment method.