知识卡片
实体定义围绕身份保持精简
设计实体时,优先保留标识它、查找它以及维持其生命周期所必需的特征和行为,其余属性可交给关联对象。原书图5.5把客户的平均销售额、产品类别移出 Customer,电话和地址则因常用于识别或匹配客户而留下。但若一个客户有多个用途不同的电话,电话可能不再有身份意义;是否保留须看领域中的匹配方式。参见[[实体身份取决于业务用途]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第05章|Entities (a.k.a. Reference Objects) · 查看原书依据
Rather than focusing on the attributes or even the behavior, strip the ENTITY object's definition down to the most intrinsic characteristics, particularly those that identify it or are commonly used to find or match it.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第36章《原书第05章|Entities (a.k.a. Reference Objects)》(源文件:_epub-src/0321125215_ch05lev1sec2.html;图5.5:05fig05.gif)
- 结论依据:原文要求实体定义围绕生命周期连续性与身份保持精简,图5.5和随后电话用途反例说明属性位置取决于实际匹配需求。
- 原始内容:But the most basic responsibility of ENTITIES is to establish continuity so that behavior can be clear and predictable. They do this best if they are kept spare. Rather than focusing on the attributes or even the behavior, strip the ENTITY object's definition down to the most intrinsic characteristics, particularly those that identify it or are commonly used to find or match it. Add only behavior that is essential to the concept and attributes that are required by that behavior. Beyond that, look to remove behavior and attributes into other objects associated with the core ENTITY . [...] The customerID is the one and only identifier of the Customer ENTITY in Figure 5.5 , but the phone number and address would often be used to find or match a Customer . The name does not define a person's identity, but it is often used as part of the means of determining it. In this example, the phone and address attributes moved into Customer , but on a real project, that choice would depend on how the domain's customers are typically matched or distinguished. For example, if a Customer has many contact phone numbers for different purposes, then the phone number is not associated with identity and should stay with the Sales Contact . (`[...]` 标明非连续省略;术语前后的空格沿用原 EPUB 标签抽取形式。)