本文介绍了协会的遍历方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Eric Evans -第5章中关于关联域驱动设计一书。他减少模型复杂性的建议之一是为关联强加遍历方向。

I'm reading the book on Domain Driven Design of Eric Evans - Chapter 5, concerning associations. One of his advices to reduce complexity of a model is to impose a traversal direction for the associations.

我引用:

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

How to chose a traversal direction for an association? Generally, when there is an association between two elements, it may be read and understood in the two directions. What may cause us to chose one direction over the other?

谢谢

推荐答案

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

When there's an association between entity A and entity B, you'll often find yourself using only A.B and never B.A. This may be because A is an aggregate root and is always your starting point, because you already have a reference to its A wherever you manipulate a B, etc.

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

I guess Evans simply suggests that you should add a traversal direction only when you need it and will use it in the code just after, as opposed to prematurely adding a traversal direction "in case we need it later".

这篇关于协会的遍历方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 15:52