简体   繁体   English

域驱动的设计-每个实体都应该有向导吗?

[英]domain-driven design - should each entity have guid?

I have ID as Guid in Order table and in OrderItem also ID as Guid. 我在订单表中有作为Guid的ID,在OrderItem中也有作为Guid的ID。 So OrderStatus (New / Confirmed / Payed / Sent) should have ID also as Guid? 因此,OrderStatus(新的/确认的/已付款的/已发送的)也应具有作为Guid的ID?

In DDD, your domain is composed from mainly two types of classes (they are others, but I'm going to focus on these two to keep it simple): 在DDD中,您的域主要由两种类型的类组成(它们是其他类,但为了简化起见,我将重点介绍这两种类型):

  1. Entities : An entity always has an ID, because the equally of an entity is based on his ID (If two entities are of the same types and their IDs are equal, then these entities are equal). 实体 :实体始终具有ID,因为实体的同等身份基于其ID(如果两个实体属于相同类型并且其ID相等,则这些实体相等)。 A good example of an entity is a person, a person is unique and can't be equivalent by its properties then a person have an ID and it's an entity. 实体的一个很好的例子是一个人,一个人是唯一的,在其属性上不能等同,那么一个人有一个ID,它就是一个实体。

  2. Value objects : A value object doesn't have an ID, because the equality of a value object is based on its properties. 值对象 :值对象没有ID,因为值对象的相等性取决于其属性。 A good example is an email address. 一个很好的例子是电子邮件地址。 Two email addresses are equal when the domain and the prefix are equal then an email address is a value object. 当域和前缀相等时,两个电子邮件地址相等,则电子邮件地址是一个值对象。

So you have to determine if OrderStatus is an entity or a value object. 因此,您必须确定OrderStatus是实体还是值对象。 If it's an entity then it have an ID. 如果是实体,则具有ID。

Hint: Based on your description it looks like it's a value object. 提示:根据您的描述,它看起来像是一个价值对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM