知识卡片
规格对象让复杂业务断言留在领域层
发票是否逾期的简单判断可以是 Invoice 方法;拖欠规则若还依赖客户宽限期、账户状态和公司政策,直接塞进 Invoice 会模糊其付款请求职责,移到应用层又使领域模型失语。Specification 是可测试候选对象的谓词式值对象,把复杂断言留在领域层。图9.12–9.13用拖欠发票作教学例子。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第09章|How to Model Less Obvious Kinds of Concepts · 查看原书依据
Business rules often do not fit the responsibility of any of the obvious ENTITIES or VALUE OBJECTS, and their variety and combinations can overwhelm the basic meaning of the domain object.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Specification,图9.12–9.13(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html)
- 结论依据:原文说明规则既不宜压垮实体,也不宜移出领域层,随后定义专用谓词式值对象。
- 原始内容:Business rules often do not fit the responsibility of any of the obvious ENTITIES or VALUE OBJECTS , and their variety and combinations can overwhelm the basic meaning of the domain object. But moving the rules out of the domain layer is even worse, since the domain code no longer expresses the model. [...] We can borrow the concept of predicates and create specialized objects that evaluate to a Boolean. Those testing methods that get out of hand will neatly expand into objects of their own. They are little truth tests that can be factored out into a separate VALUE OBJECT . [...] A SPECIFICATION is a predicate that determines if an object does or does not satisfy some criteria.