知识卡片
仓储可按类型替换存储实现
仓储代表一个类型的对象集合,该类型可为具体类、抽象父类或接口,不必每个具体类各建一仓储。客户端依赖仓储接口后,实现可改用不同数据库、缓存或测试用内存集合;但持久化技术是否支持多态会限制具体方案。原书图6.21展示仓储将存储和映射委托给基础设施,替换能力来自接口边界,不能假定所有实现性能相同。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第06章|Repositories · 查看原书依据
You can facilitate testing of the client code and the domain objects by providing an easily manipulated, dummy in-memory strategy.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第46章《原书第06章|Repositories》(源文件:_epub-src/0321125215_ch06lev1sec3.html;图6.21)
- 结论依据:原文说明仓储的“类型”可以抽象或具体,客户端解耦后可替换查询、缓存、持久化及测试实现,同时提醒数据库多态能力限制。
- 原始内容:A REPOSITORY "contains" all instances of a specific type, but this does not mean that you need one REPOSITORY for each class. ... You can facilitate testing of the client code and the domain objects by providing an easily manipulated, dummy in-memory strategy.