I know that associations in class diagram can be bi-directional or directional. We refer to this as navigability. I am not sure to fully understand what it means.
Please consider the following example :
Does the navigability in the example meant that we read this association as "one order detail is related to one item " and that we cannot read it in the opposite direction as for one Item it can have zero to many Order item ? Finally , how is navigability implemented as a code ?
Best Answer
Navigability means according to the UML specifications:
In your example, this means that:
the association can be read in both ways; navigability does not change the fact that there is an association with two sides;
an instance of
OrderDetail
can easily and efficiently find the associatedItem
object;it is not guaranteed that
Item
could find all its associatedOrderDetails
, and if it could, it might not be efficient;navigability has nothing to do with the multiplicity.
There is no rule about how to implement such a link. This is completely implementation dependent. Examples for your case:
OrderDetailTable
would have a mandatoryItemId
column with theId
of the relatedItem
, and theItemTable
would haveId
as primary key. As a consequence, it would be extremely efficient to find theItem
fir navigation. It would also be possbile to find all theOrderDetails
that are related to anItem
, but it might not be as efficient if the necessary indexes are not created.OrderDetail
class could have a integer memberItemId
. You could have anItemRepository
class with a methodfindById()
that would return for a given integer the correspondingItem
instanceOrderDetail
class a member that points to a specificItem
. In this case, the opposite navigation is practically impossible if there isn't a pointer in the other direction.As you see, this in very dependent of the implementation language, the related idioms and techniques chosen (e.g. integer id vs pointer). It also depends on the multiplicities, the kind of ownership, as well as access path designed for other associated classes.