uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Reflexive Associations

A reflexive association is an association from a class to itself. There are two main types: Symmetric and Asymmetric.

Asymmetric Reflexive Associations: The ends of the association are semantically different from each other, even though the associated class is the same. Examples include parent-child, supervisor-subordinate and predecessor-successor.

The first and second examples below show courses having prerequisites that are other courses. It is necessary to specify a role name at one or both ends of the association to distinguish the ends. Also it is necessary to ensure that the lower bound is always zero on both ends. The reason for this is that otherwise an illogical situation would arise: For example, if you said that each course must have one or more pre-requisites, then what about the very first courses in the hierarchy? The compiler will report an error if the lower bound on a multiplicity is one or higher.

The following is how an asymmetric reflexive association appears in UML, as generated by UmpleOnline. The corresponding Umple code is in the first example below.

UML Class course with asymmetric reflexive many-many association with role names prerequisites and successors  

Symmetric Reflexive Associations: There is no logical difference in the semantics of each association end. The fourth example shows one of these: A set of courses that are mutually exclusive with each other essentially make up a set. If course A is mutually exclusive with B, then course B is mutually exclusive with A. In other words, students who have taken one course cannot take another in the set. Umple uses the keyword 'self' to identify this case. Note that at the current time the asociaton itself does not appear in UmpleOnline; this will be fixed.

 

Example

// Example asymmetric association with role names on both ends
class Course {
  * successor -- * Course prerequisite;
}

      

Load the above code into UmpleOnline

 

Another Example

// Example asymmetric association with role name on one end
class Course {
   * -- * Course prerequisite;
}

      

Load the above code into UmpleOnline

 

Another Example

// Example asymmetric association with role name on the other end
class Person {
   0..2 parents -- * Person;
}

      

Load the above code into UmpleOnline

 

Another Example

// Example symmetric association. Note the use of the keyword self
class Course {
   * self  isMutuallyExclusiveWith;
}

      

Load the above code into UmpleOnline

 

Syntax


symmetricReflexiveAssociation : [[multiplicity]] self [roleName] ;