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

Advertisement

About Andrea Baruzzo

Andrea Baruzzo is an author, a research fellow of the University of Udine, and an independent consultant. He has a strong experience in UML modeling and object-oriented technology, applying OOA/OOD in a wide variety of business applications. As a technical author he is a columnist on the magazine “Computer Programming” since 1999 and since 2003 he writes regularly for the column "Object-Oriented Design". As a research fellow, he is actively involved in the following two main areas: - software engineering, concerning in particular the automatic validation and verification of models; - knowledge representation, information filtering and retrieval; - [semantic] digital libraries, semantic Web, and service-oriented architectures (SOA). Andrea Baruzzo’s Specialties: Helping development teams to bridge the gap between analysis and design using models. Getting all team members to speak the same language, distilling the core of a complex domain and distilling out implicit knowledge in the models.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.