知识卡片
库存与混合颜料分开建模
原书教学例子将颜料概念分成不可变原料 StockPaint 与组合结果 MixedPaint:mixIn 只把原料加入后者的组成集合;结果体积由原料体积求和,颜色由颜料色值计算。这样既能显示用过哪些原料,也不必假装原料被物理消耗。图10.10画的是概念重构后的职责,测试中1.0与1.5合为2.5只是示例期望,不代表已有实测。mixIn 仍是修改命令;取体积和颜色的操作可保持无副作用。参见[[颜料颜色计算移入值对象]]。
结构图:
classDiagram
class Paint {
getVolume() double
getColor() PigmentColor
}
class StockPaint {
volume
color
}
class MixedPaint {
mixIn(stock) void
stockConstituents()
}
Paint <|-- StockPaint
Paint <|-- MixedPaint
MixedPaint --> "*" StockPaint : constituents
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第10章|Assertions · 查看原书依据
Now there is only one command, mixIn(). It just adds an object to a collection, an effect apparent from an intuitive understanding of the model. All other operations are SIDE-EFFECT-FREE FUNCTIONS. A test method confirming one of the ASSERTIONS listed in Figure 10.10 could look something like this (using the JUnit test framework):
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第75章《Assertions》(源文件:_epub-src/0321125215_ch10lev1sec3.html;图10.10;单元02)
- 结论依据:原文和图10.10把 Paint 分为 Stock Paint 与 Mixed Paint,后者持有原料集合;`mixIn` 添加成员,`getVolume` 求和,`getColor` 用 Pigment Color 混合计算。测试代码给出1.0与1.5得到2.5的示意断言。
- 原始内容:Now there is only one command, mixIn(). It just adds an object to a collection, an effect apparent from an intuitive understanding of the model. All other operations are SIDE-EFFECT-FREE FUNCTIONS. A test method confirming one of the ASSERTIONS listed in Figure 10.10 could look something like this (using the JUnit test framework):