[ Team LiB ] Previous Section Next Section

Multiplicity

The multiplicity of a property is an indication of how many objects may fill the property. The most common multiplicities you will see are

  • 1 (An order must have exactly one customer.)

  • 0..1 (A corporate customer may or may not have a single sales rep.)

  • * (A customer need not place an Order and there is no upper limit to the number of Orders a Customer may place梲ero or more orders.)

More generally, multiplicities are defined with a lower bound and an upper bound, such as 2..4 for players of a game of canasta. The lower bound may be any positive number or zero; the upper is any positive number or * (for unlimited). If the lower and upper bounds are the same, you can use one number; hence, 1 is equivalent to 1..1. Because it's a common case, * is short for 0..*.

In attributes, you come across various terms that refer to the multiplicity.

  • Optional implies a lower bound of 0.

  • Mandatory implies a lower bound of 1 or possibly more.

  • Single-valued implies an upper bound of 1.

  • Multivalued implies an upper bound of more than 1: usually *.

If I have a multivalued property, I prefer to use a plural form for its name.

By default, the elements in a multivalued multiplicity form a set, so if you ask a customer for its orders, they do not come back in any order. If the ordering of the orders in association has meaning, you need to add {ordered} to the association end. If you want to allow duplicates, add {nonunique}. (If you want to explicitly show the default, you can use {unordered} and {unique}.) You may also see collection-oriented names, such as {bag} for unordered, nonunique.

UML 1 allowed discontinuous multiplicities, such as 2, 4 (meaning 2 or 4, as in cars in the days before minivans). Discontinuous multiplicities weren't very common and UML 2 removed them.

The default multiplicity of an attribute is [1]. Although this is true in the meta-model, you can't assume that an attribute in a diagram that's missing a multiplicity has a value of [1], as the diagram may be suppressing the multiplicity information. As a result, I prefer to explicitly state a [1] multiplicity if it's important.

    [ Team LiB ] Previous Section Next Section