gpt4 book ai didi

domain-driven-design - 协会的遍历方向

转载 作者:行者123 更新时间:2023-12-04 08:22:07 24 4
gpt4 key购买 nike

我正在阅读有关的书的域驱动设计的书埃里克·埃文斯(Eric Evans)-,第5章,涉及关联。他减少模型复杂性的建议之一是为关联强加一个遍历方向。

我引用:

It is important to constrain relationships as much as possible. A bidirectional association means that both objects can be understood only together. When application requirements do not call for traversal in both directions, adding a traversal direction reduces interdependence and simplifies the design. Understanding the domain may reveal a natural directional bias.



如何选择关联的遍历方向?通常,当两个元素之间存在关联时,可以在两个方向上进行阅读和理解。是什么导致我们选择一个方向而不是另一个方向?

谢谢

最佳答案

当实体A和实体B之间存在关联时,您经常会发现自己仅使用A.B,而从未使用B.A。这可能是因为A是聚合根并且始终是您的起点,因为无论您在哪里操纵B都已经引用了A。

我想Evans只是建议您仅在需要时才添加遍历方向,然后在代码中立即使用它,而不是“在以后需要时”过早添加遍历方向。

关于domain-driven-design - 协会的遍历方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9804815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com