知识卡片
工厂一次产出有效聚合
工厂的单次创建调用须原子地得到满足不变量的产品:创建实体时,至少形成有效的整个聚合,非必需细节可稍后添加;创建不可变值对象时,全部属性须达到最终状态。若请求无法生成有效对象,应以明确失败机制拒绝,不能返回无效产品。接口应按调用方需要的抽象类型表达产品,并隐藏内部装配与具体类。参见[[聚合内不变量随事务检查]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第06章|Factories · 查看原书依据
Each creation method is atomic and enforces all invariants of the created object or AGGREGATE. A FACTORY should only be able to produce an object in a consistent state.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第45章《原书第06章|Factories》(源文件:_epub-src/0321125215_ch06lev1sec2.html;图6.12)
- 结论依据:原文列出好工厂的两项要求:每个创建方法原子执行并维护全部不变量,以及按期望的抽象类型而非具体实现提供接口;无效请求必须有不返回无效值的处理。
- 原始内容:Each creation method is atomic and enforces all invariants of the created object or AGGREGATE . A FACTORY should only be able to produce an object in a consistent state. ... The FACTORY should be abstracted to the type desired, rather than the concrete class(es) created.