返回主题:数据入口与工作单元

知识卡片

普通读书笔记卡 · 1971.o.1.b.4.d.1.c.4.c

仓储找旧对象工厂造新对象

理解等级:中级

工厂负责新对象的创建与复杂装配;仓储负责查找既有对象及其存取。仓储取回记录时可委托工厂重建实例,但概念上仍是原实体,身份不变;新对象则由客户端经工厂创建后加入仓储。原书图6.22–6.23展示这两条路径。技术上重建也会实例化对象,职责上仍应区分“新建”和“找回”。参见[[重建实体须保留原身份]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第46章《原书第06章|Repositories》(源文件:_epub-src/0321125215_ch06lev1sec3.html;图6.22–6.23) - 结论依据:原文区分新对象创建与旧对象查找,允许仓储委托工厂重建,并用两图分别展示查旧对象和新对象存储路径。 - 原始内容:The FACTORY makes new objects; the REPOSITORY finds old objects. The client of a REPOSITORY should be given the illusion that the objects are in memory. ... These two views can be reconciled by making the REPOSITORY delegate object creation to a FACTORY , which (in theory, though seldom in practice) could also be used to create objects from scratch.