Multiplicity

So far we hae only talked about one-to-one relationships (Each lamp has one bulb, each bulb is in one lamp), but there may of course be different multiplicities.

Important

Multiplicity

for an attribute or association defines "how many" of this attribute or association there are. Multiplicity is given with as mininum number, dots ( .. ), and maximum number.

Multiplicity only takes whole numbers, no negatives!

Examples: A car usually has 4..5 wheels, a class has 0..75 students.

Shortcuts:

  • if both numbers are the same, the .. and the second number can be omitted, e.g. a twin-lamp has 2 bulbs

  • if the upper limit is unlimited a * is used: A city has 1..* houses, a novel has 100..* words

  • 0..* can be written as *

Common multiplicities:

  • 0: A class has never any of this attribute (not really used)

  • 0..1: A class has none or one of the specified (e.g. a lamp has a bulb or has none, a person has a job or has none)

  • *: Any arbitray number of attributes: A file has any number of bytes

  • 1: Exactly one: The hominoid has exactly one position

  • 1..*: At least one, but any number: A poem has at least one word, but can be infinitely long.

If multiplicity is ommited, it usually means 1 or 0..1.

On attributes, multiplicity is shown in square brackets after the attribute, e.g. [2], [*], [1..4]

Example 3.10. Multiplicity on attributes

On associations, the multiplicy is shown without square brackets on the class that is multiplied:

Example 3.11. Multiplicity on associations

Example 3.12. A timer for multiple bombs

Practice: assume a modern timer that can detonate up to 8 bombs at a time. Show the classes for Timer and Bomb and their association. You may use the shortened notation for the classes.