知识卡片

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

关联方向应按业务查询裁剪

理解等级:中级

现实关系常可双向理解,但模型不必默认双向遍历。若业务只会“从国家查历任总统”,就保留国家到人物的方向;不让人物对象因罕用的反向查询依赖“总统”概念。这样能减少对象间牵连,也揭示哪种查询对领域更有意义。若双向查找确属业务语义或功能所需,仍应保留双向;无关核心任务的关联则可删除。参见[[关联规定可遍历行为]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第35章《原书第05章|Associations》(源文件:_epub-src/0321125215_ch05lev1sec1.html;图5.1:05fig01.gif) - 结论依据:原文用国家与总统的关系说明按自然查询方向将双向关联收束为单向,并说明确有语义或功能需要时保留双向,非必要关联可彻底移除。 - 原始内容:When application requirements do not call for traversal in both directions, adding a traversal direction reduces interdependence and simplifies the design. ... When the bidirectionality of a relationship is a semantic characteristic of the domain, when it's needed for application functionality, the retention of both traversal directions conveys that.