Discontinuous multiplicity in UML Class diagram

Viewed 46

I just have a quick question regarding multiplicities on unary associations in UML. So I want to specify that an instance of a class is linked to either non or two instances of the same class. Can I express this by putting the multiplicity as "0, 2" or is this not allowed?

1 Answers

No it isn't. A multiplicity is expressed as a combination of a lower-bound and an upper-bound.

From the UML 2.5 specs

The multiplicity bounds may be shown in the format:

<lower-bound> ‘..’ <upper-bound>

If you want to express either 0 or 2 you'll have to use multiplicity 0..2 and add an extra contraint to express the fact that cardinality 1 is not allowed. This can be simply done by attaching a constraint like { cardinality must be 0 or 2 }.

Related