Association traversal direction

I am reading a book on Driven Design by Eric Evans - Chapter 5 on associations.One of his tips for reducing model complexity is to overlay traversal directions for associations.

I quote:

It is important to limit the relationship as much as possible. bi-directional association means that both objects can only be understood together. When application requirements do not require traversal in both directions, adding a traversal direction reduces interdependencies and simplifies design. Understanding the domain can reveal natural directional bias.

How do I choose a traversal direction for an association? Typically, when there is a relationship between two elements, it can be read and understood in two ways. What can make us choose one direction over another?

thank

+3


source to share


2 answers


When there is a relationship between entity A and object B, you often find that you only use AB and never BA This may be because A is an aggregate root and is always a starting point because you already have a reference to its A wherever you manipulate B, etc.



I think Evans simply assumes that you should add a traversal direction only when you need it, and use it in your code immediately after it, as opposed to prematurely adding a traversal direction "if needed" later.

+4


source


Conceptually, all associations are bidirectional. However, when implemented, most of them become unidirectional, since you just need to maintain links from one of the participants.



At design time, you can specify that the inability to break the bidirectional implementation at the implementation level and make the system easier to code.

+4


source







All Articles