# About cardinalities and multiplicities in UML associations

According to The Unified Modeling Language Reference Manual (2/E), the cardinality is a specific number, representing the number of elements in a collection. Many authors misuses the term, meaning instead the range specification of allowable cardinality values (i.e. the size) assumed by a collection during its life-cycle, which is properly called multiplicity.

Apart from this terminological issues, multiplicities can constraint associations in many different ways, more than those usually used in practice. Indeed, in many models the multiplicities for one role ranges according to:

• an interval, such as 1..4, which means “one to four, inclusive”;
• a fixed number, such as “1”, or MAX_VALUE (which are a different way to write the interval 1..1, and MAX_VALUE..MAX_VALUE, respectively);
• an asterisk (*), which is an abbreviation for 0..* (“zero or more, inclusive”).

Because the multiplicity is probably the most important property of an association, it can be useful (as it was for me) to know that there are also two other possibilities allowed [1]:

• a comma separated list, such as “3,5,7”, which means “three, five, or seven”;
• a combination of a list and a range, such as “1..10, 25”, which means “one to ten, inclusive, or 25″.

The reference manual provides also a specification for ordering associated to multiplicities. More in particular, the following keywords imply a specific order property:

• set: unordered, unique elements (it is the default for any multiplicity);
• bag: unordered, nonunique elements;
• ordered set: ordered, unique elements;
• list (or sequence): ordered, nonunique elements.

Thus, we can write the following multiplicity constraints in association roles:

• * {list}, which means “any number of elements in the range 0..*, ordered, possibly with duplicates”;
• 1..* {ordered}, which means “one or more, ordered, unique elements”;
• 1..6 {bag}, which means “any number between 1 and 6, unordered, possibly with duplicates”.

### Bibliography

[1] Douglass, B.P. – “Real Time UML Workshop for Embedded Systems“, Newnes, 2006