知识卡片
独立类隔离复杂计算
独立类(Standalone Class)把可独立理解的完整概念及其复杂计算放进一个几乎不依赖其他领域类的对象。原书颜料混合教学例子里,Paint 需要知道颜色,但 Pigment Color 的计算无需知道 Paint;留下有意义的单向依赖,颜色计算便可单独理解和测试。
目标是剔除非必要依赖,不是为追求零依赖把丰富的领域模型都压成原始值。两个概念天然紧密相关时,应保留能解释其关系的连接;这也减轻阅读整个模块时需同时记住的概念量。参见[[隐性概念同样形成依赖]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第10章|Standalone Classes · 查看原书依据
The concept of paint is fundamentally related to the concept of color. But color, even of pigment, can be considered without paint. By making these two concepts explicit and distilling the relationship, the remaining one-way association says something important, and the Pigment Color class, where most of the computational complexity lies, can be studied and tested alone.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第77章《Standalone Classes》(源文件:_epub-src/0321125215_ch10lev1sec5.html;单元01)
- 结论依据:原文建议把复杂计算析出为独立类或值对象,颜料与颜色的单向关系使 Pigment Color 可独立测试;也明确不应为消除依赖而退化为原始值。
- 原始内容:The concept of paint is fundamentally related to the concept of color. But color, even of pigment, can be considered without paint. By making these two concepts explicit and distilling the relationship, the remaining one-way association says something important, and the Pigment Color class, where most of the computational complexity lies, can be studied and tested alone.