在阅读DDD之后,我了解到我的用户是实体对象 – 我使用他们的唯一ID来引用它们.
当一个用户“跟随”另一个用户(即形成连接)时,该关系存储在多对多表中.其字段包括FollowerID,TargetID和Status.每个Follower / Target组合只能有两个记录(一个是Active,另一个是Inactive),所以我可以根据它们的属性安全地识别对象.
所以,我认为我的Connection对象是Value Objects,而不是Entity Objects,但我不确定.你能帮我解决这个问题吗?
解决方法
因此,我会说Connection是一个值对象.
为了支持我的结论,Microsoft.Net Architecting Applications for the Enterprise,第187页说:
A value object class represents an entity in the domain that mostly
contains data and lives for the data it contains. A value object is
fully identified by a combination of values it contains. An entity
object,on the other hand,has its own life and rich behavior
regardless of the data it contains. Entity objects are usually objects
with a longer lifetime. A value object represents an aspect of an
entity and can live only in relation to an entity.
另请参阅第189页:
One further comment is needed to explain the difference between entities and value objects. You don’t need a repository or a data mapper for a value object. You need a repository only for an entity. The repository (or the mapper) for a given entity will certainly take care of all value objects that depend on a given entity.