知识卡片
工厂接口应控制输入依赖
设计工厂方法时,单次调用须取得构成有效产品所需的全部输入,并约定不变量失败时的返回或异常方式。参数会让工厂依赖其类型:直接传给产品的依赖较弱,从参数内部拆取多项数据则更紧。优先用较基础层的抽象,或与产品本就紧密关联的对象;不要因为工厂已了解产品具体类,就把参数也固定为具体类。原书采购单行项接收目录部件,是已有概念关联的例子。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第06章|Factories · 查看原书依据
You have to pass in everything needed to create a complete product in a single interaction with the FACTORY.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第45章《原书第06章|Factories》(源文件:_epub-src/0321125215_ch06lev1sec2.html;小节 Designing the Interface)
- 结论依据:原文提出操作原子性、失败策略、参数耦合程度和参数抽象类型四项接口设计考虑,以采购单行项和目录部件说明已有自然依赖。
- 原始内容:You have to pass in everything needed to create a complete product in a single interaction with the FACTORY . ... Use the abstract type of the arguments, not their concrete classes.