知识卡片
工厂位置由控制关系决定
工厂放在哪里,取决于创建控制权与产品的自然关系:
| 场景 | 位置 | 原书示例 |
|---|---|---|
| 为已有聚合添加内部成员 | 聚合根上的工厂方法 | 采购单创建行项(图6.13) |
| 一个对象掌握新对象所需数据与规则 | 与产品紧密相关的对象上的工厂方法 | 券商账户创建独立聚合的交易单(图6.14) |
| 无自然宿主或装配细节复杂 | 独立工厂 | 券商账户工厂交付聚合根(图6.15) |
内部成员即使由独立工厂创建,也须遵守[[聚合根限定外部引用]]的边界规则;这些图是原书教学示例。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第06章|Factories · 查看原书依据
A FACTORY is very tightly coupled to its product, so a FACTORY should be attached only to an object that has a close natural relationship with the product.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第45章《原书第06章|Factories》(源文件:_epub-src/0321125215_ch06lev1sec2.html;图6.13–6.15)
- 结论依据:原文先给出控制权原则,再分别讨论聚合根工厂方法、自然关联对象上的工厂方法和独立工厂,图示对应采购单、交易单及券商账户。
- 原始内容:Generally speaking, you create a factory to build something whose details you want to hide, and you place the FACTORY where you want the control to be. ... A FACTORY is very tightly coupled to its product, so a FACTORY should be attached only to an object that has a close natural relationship with the product.