知识卡片
跨对象约束可成为模型对象
当约束需用到宿主对象本不负责的数据、重复出现在不相关对象里,或在业务讨论中很重要却埋在过程代码里,独立建模可让它有合适的责任位置。原书回顾货运超订:Overbooking Policy 表达 Voyage 与 Cargo 关联上的容量规则;10% 是书中案例数值,不是通用超订比例。参见[[约束规则需要显式命名]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第09章|How to Model Less Obvious Kinds of Concepts · 查看原书依据
In Chapter 1, we worked with a common shipping business practice: booking 10 percent more cargo than the transports could handle. (Experience has taught shipping firms that this overbooking compensates for last-minute cancellations, so their ships will sail nearly full.) This constraint on the association between Voyage and Cargo was made explicit, both in the diagrams and in the code, by adding a new class that represented the constraint.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Explicit Constraints,图9.11(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html)
- 结论依据:原文列出约束扭曲宿主对象的信号,并以超订策略说明关系约束对象。
- 原始内容:Here are some warning signs that a constraint is distorting the design of its host object. Evaluating a constraint requires data that does not otherwise fit the object's definition. Related rules appear in multiple objects, forcing duplication or inheritance between objects that are not otherwise a family. A lot of design and requirements conversation revolves around the constraints, but in the implementation, they are hidden away in procedural code. When the constraints are obscuring the object's basic responsibility, or when the constraint is prominent in the domain yet not prominent in the model, you can factor it out into an explicit object or even model it as a set of objects and relationships. [...] In Chapter 1 , we worked with a common shipping business practice: booking 10 percent more cargo than the transports could handle. (Experience has taught shipping firms that this overbooking compensates for last-minute cancellations, so their ships will sail nearly full.) This constraint on the association between Voyage and Cargo was made explicit, both in the diagrams and in the code, by adding a new class that represented the constraint.