uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Multiplicity

Multiplicity describes the allowable number of entities that can participate in one end of an association. In most cases you provide both a lower and upper bound, but the "many" (or "*") case assumes a zero lower bound.

The most common cases are:

  • * meaning 'any number' or 'many'; i.e. from 0 to whatever number the computer can handle.
  • 1 meaning 'mandatory', i.e. exactly one.
  • 0..1 meaning 'optional', i.e. a lower bound of zero, and an upper bound of one.
  • 1..* meaning 'mandatory many', i.e. a lower bound of 1 and an indeterminate upper bound.

Multiplicity must be specified for both ends of an association. At run time, code generated by Umple will ensure that the lower bounds and upper bounds are respected. Also the multiplicity determines which methods will be generated in the API for the model. For example, when * is specified, methods are generated to access all the associated objects, and to access an object at a specific index. The number of objects linked at run-time is called 'cardinality'.

If multiplicity is specified incorrectly, the compiler will generate an error message highlighting the line with the multiplicity error.

 

Example

// When multiplicity is given as *, which is the same as 0..*
// there can be any number of links from an instance at the other end
// of the association to instances at this end 
//
// The lower bound is zero and the upper bound is 'many'
// When multiplicity is given as *, which is the same as 0..*
// there can be any number of links from an instance at the other end
// of the association to instances at this end 
//
// The lower bound is zero and the upper bound is 'many'
class A
{
  // an instance of A has many B's
  1 -- * B;
  
  // An instance of C has many A's
  * -- 1 C;
}

class B {} class C {}
      

Load the above code into UmpleOnline

 

Another Example

// When the mutiplicity is shown as two integers separated by ..
// then the first integer is the lower bound, and the second integer
// is the upper bound.
//
// Here, at one end of the association
// the lower bound is 0..1 (which means 'optional'
// and at the other end of the association
// the lower bound is 3 and the upper bound is 5
class D {
  0..1 -- 3..5 E;
}

class E{}

      

Load the above code into UmpleOnline

 

Another Example

// When the multiplicity is a single integer there must be
// exactly that number of objects linked at all times (including
// when the object at the other end is first created).
// These multiplicities are rare
// Here, there must be exactly two objects (lower and upper bound are both 2)
class F {
  0..1 -- 2 G;
}

class G{}

      

Load the above code into UmpleOnline

 

Syntax


multiplicity- : [!lowerBound:\d+|[**]] .. [!upperBound:\d+|[**]] | [!bound:\d+|[**]]