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.
I quote:
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.
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?
Thanks
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.
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".
Conceptually all associations are bidirectional. Nevertheless, when implementing them most end up being unidirectional since then you just need to maintain the links in one of the participants.
During design you may want to indicate the navegability to break the bidirectionality at the implementation level and facilitate the coding of the system
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With