知识卡片
规格组合实现须权衡对象开销
规格的 AND/OR/NOT 是领域表达能力,底层可有不同实现。原书先用 Composite:每个组合创建一个规格对象,代码易读;但对象数据库若给每个细粒度对象分配 ID 和跟踪成本,对象数可能成为负担。作者自述曾在一个项目中因此产生数百万细粒度对象并拖慢系统,这是原书项目经历,不能外推到所有数据库。
另一个示意实现把表达式编码为字符串或数组、运行时解释,可减少对象数和内存,却要求开发者理解更复杂的解释逻辑。只需 AND 时不必先实现 OR/NOT;应按场景选择实现,同时保持规格概念与外部契约不变。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第10章|A Declarative Style of Design · 查看原书依据
I employed SPECIFICATIONS at some important points in the domain design, which I think was a good decision. But I used a slightly more elaborate version of the implementation described in this chapter, which was definitely a mistake. It resulted in millions of very fine grained objects that contributed to bogging the system down.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第81章《A Declarative Style of Design》(源文件:_epub-src/0321125215_ch10lev1sec8.html;单元03)
- 结论依据:原文明确称 Composite 代码仅为讲解示例,并叙述作者对象数据库项目中对象开销造成问题;随后比较表达式编码实现的低对象数与更高开发难度。
- 原始内容:I employed SPECIFICATIONS at some important points in the domain design, which I think was a good decision. But I used a slightly more elaborate version of the implementation described in this chapter, which was definitely a mistake. It resulted in millions of very fine grained objects that contributed to bogging the system down.