知识卡片
享元优化不等于领域模式
有限种类的值对象被大量重复使用时,可以用 Flyweight 共享实例,减少实现开销。原书以房屋平面图中反复出现的电源插座作例子;这是值对象的实现选项,不描述领域里新的概念关系,也不适用于需保持独立身份的实体。
相较之下,Composite 若确实表达领域中的整体—部分关系,就同时影响模型语义和实现。判断设计模式能否成为领域模式,应看它是否说明了领域概念,而非只解决技术问题。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第12章|Why Not F LYWEIGHT? · 查看原书依据
When a limited set of VALUE OBJECTS is used many times (as in the example of electrical outlets in a house plan), it may make sense to implement them as FLYWEIGHTS. This is an implementation option available for VALUE OBJECTS and not for ENTITIES.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第90章《Why Not FLYWEIGHT?》(源文件:_epub-src/0321125215_ch12lev1sec3.html;单元01)
- 结论依据:原文明确Flyweight是值对象的实现选项而非领域模型概念,并与同时影响模型和实现的Composite对比。
- 原始内容:When a limited set of VALUE OBJECTS is used many times (as in the example of electrical outlets in a house plan), it may make sense to implement them as FLYWEIGHTS . This is an implementation option available for VALUE OBJECTS and not for ENTITIES .