知识卡片
别扭后置条件暴露缺失概念
在原书颜料商店教学例子中,p1.mixIn(p2) 增加 p1 体积却不减少 p2,与“把一桶倒入另一桶”的直觉冲突。把这个后置条件写出来后,团队才发现应用还要列出参加混合的原始颜料;直接把 p2 清零虽符合物理直觉,却破坏该展示需求。契约别扭可能提示模型把“库存原料”和“混合结果”混作一个概念;先核业务用途,再考虑拆概念,而非仅把现有怪规则写进文档或机械修正数据。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第10章|Assertions · 查看原书依据
The trouble is, developers are going to make mistakes, because these properties don't fit the concepts we have invited them to think about. The straightforward fix would be change the volume of the other paint to zero. Changing an argument is a bad practice, but it would be easy and intuitive. We could state an invariant: Total volume of paint is unchanged by mixing.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第75章《Assertions》(源文件:_epub-src/0321125215_ch10lev1sec3.html;图10.9;单元02)
- 结论依据:原书先明列接收者体积增加、参数颜料不变的后置条件,再揭示原料清单展示需求,因此物理直觉式清零会误改应用语义;作者据此寻找缺失概念。
- 原始内容:The trouble is, developers are going to make mistakes, because these properties don't fit the concepts we have invited them to think about. The straightforward fix would be change the volume of the other paint to zero. Changing an argument is a bad practice, but it would be easy and intuitive. We could state an invariant: Total volume of paint is unchanged by mixing.