umlocl

OCL - Composition relation, can it be referenced backwards?


So suppose that I have a simple relation where a "Car" is composed of "Wheel" (Through "has" relation).

I know that in the context of Car, I can navigate, in OCL, easily to see the wheel associated with this car, by writing self.has to obtain a set of "Wheel" linked to this "Car".

However, with such composition relation (in contrast with a unidirectional association), would it be possible to navigate back to "Car" being in the context of "Wheel" ? If yes, how should it be done ? (If, for a certain reason, we need to work in the context of "Wheel" and not "Car". Just for the sake of this question)


Solution

  • All associations in OCL can be navigated in either direction. Section 7.5.4 of the OCL spec explains how the unspecifed role name is deduced from the remote type name, e.g. self.Car and in the case of ambiguity by self.Car[Car::has].

    NB. It is makes no difference whether the UML definition is of a uni- or bi-directional association. UML or Ecore defines the run-time navigability. OCL is concerned with analysis/compile-time visibility; all associations are navigable in all directions.