开发者

Should Comment History be an Entity,DDD

开发者 https://www.devze.com 2023-02-26 18:58 出处:网络
I\'m currently designing a web application using DDD methodology. While distinguishing the Entities from value objects, Icame across one such model element which I\'m unable to decide to pla开发者_如

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 pla开发者_如何学Goce 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?


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:

Entity:
An object that is not defined by its attributes, but rather by a thread of continuity and its identity.

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" to Country. If country was a value object, every time new citizen born, whole country would be needed to be reconstructed.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消