Let’s say that in the game, a player has a pet:
Player<>——Pet
Obviously player can access Pet’s fields and methods, but I assume Pet does not know about the player?
I need that Pet can access the player as well, how should I model that?
In UML, an aggregation relationship has a directionality, which can be
-
uni-directional, where the
Player
knows about thePet
, but not the other way around. This is usually indicated with an arrow on the end of the line:Player <>——> Pet
-
bidirectional, where both the
Player
and thePet
can access each other. This is usually indicated by the absence of an arrow (like you used in the question):Player <>——- Pet
In most programming languages, there is no real equivalent of the bidirectional relation, so it is usually emulated by using two uni-directional relations (pointers/references) and a bit of logic to ensure that if you follow both links, you end up back in the same object.
2