知识卡片
搜索与关联遍历共同设计对象入口
取得已有对象的引用,既可从已知对象沿关联遍历,也可按属性搜索持久化对象。前者表达对象关系,却可能迫使模型保存过多连接;后者能直达目标、降低关联耦合,却可能弱化有意义的业务关联。原书以“顾客持有全部订单集合”还是“按顾客 ID 查询订单”说明这是领域设计判断,不能只随数据库便利性决定。数据库取回后重组的是同一个概念实体,不是新顾客。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第06章|Repositories · 查看原书依据
Whether to provide a traversal or depend on a search becomes a design decision, trading off the decoupling of the search against the cohesiveness of the association.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第46章《原书第06章|Repositories》(源文件:_epub-src/0321125215_ch06lev1sec3.html;开篇)
- 结论依据:原文对照沿关联遍历与数据库查询,讨论搜索的解耦和关联的内聚,并明确从存储中重组实例不产生新的概念实体。
- 原始内容:Whether to provide a traversal or depend on a search becomes a design decision, trading off the decoupling of the search against the cohesiveness of the association. ... A Customer object does not represent a new customer just because we stored it in a database and retrieved it.