uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   


Association Specializations

A specialization is a subset of duplicate associations where:

  • the role names are identical;
  • the associated types form a hierarchical structure (i.e. the specialized types are subclasses);
  • and the multiplicites are more specific than that of the previously defined association.

For example, consider the case of Vehicle and Wheel classes and an Optional One to Many association between them. A Wheel can only belong to one Vehicle, but the concept of a Vehicle can include any number of Wheels. Say, for instance, we wanted to create a new Bicycle class that extends Vehicle, but we would like to make use of the association that already exists with a stricter multiplicity (say, a Bicycle can have up to 2 Wheels).


Without specialiations, we need to create a new association between Bicycle and Wheel and thus generate some unneeded code and duplicate data fields (both Vehicle and Bicycle would have a list of Wheels, which behave more or less the same). With specializations, simply stating that we want a new association between Bicycle and Wheel (as long as the names match up to the Vehicle to Wheel association) is enough to generate more appropriate code.



// Here we define our base classes
class Vehicle {}
class Wheel {}

// Here we define our subclasses
class Bicycle { isA Vehicle; }
class Unicycle { isA Vehicle; }

// This is the "parent association" so to speak.
// It defines the Vehicle to Wheel relationship with
// as much abstraction as possible.
association { 0..1 Vehicle vehicle -- 0..* Wheel wheel; }

// Here, we'd like to extend the functionality of the 
// previous association to work with subclasses of Vehicle,
// while utilizing as much of the existing code as possible.
// Specializations allow us to do this, since:
// -> Bicycle and Unicycle extend Vehicle;
// -> Wheel is part of the Wheel hierarchy;
// -> The bounds on the left are not less specific than
//    the left bound of the parent association;
// -> The bounds on the right are not less specific than
//    the right bound of the parent association;
// -> Finally, the role names are the same.
association { 0..1 Bicycle vehicle -- 0..2 Wheel wheel; }
association { 0..1 Unicycle vehicle -- 0..1 Wheel wheel; }


Load the above code into UmpleOnline