Pergunta

I would like to know once and for all how to write UML cardinalities, since I very often had to debate about them (so proofs and sources are very welcome :)

If I want to explain that a Mother can have several Children but a Child has one and only one Mother, should I write:

Mother * ---------- 1 Child

Or

Mother 1 ---------- * Child

?

Foi útil?

Solução

the second one Mother 1 ----------------- 1..* Child

You would find many example in the UML specification for all figure related to the Abstract Syntax...

Outras dicas

Of course Red Beard is right, the correct answer is the second one.

As for a tip for remembering this, I advise to think in english: You say "A child has ONE mother", and in this sentence like in UML, ONE is written next to Mother. Fairly simple.

Many people have this question when they start using UML, especially when they come from another notation where the names are always read clockwise, regardless of which end of the line they're on. That's really confusing!

Red Beard is correct, although the UML spec does not explicitly state where association-end information (i.e., name and multiplicity) is written, it implies it in several places. For example, Figures 7.11 (showing attributes) and 7.12 (showing unidirectional associations with association ends next to the arrowheads) are equivalent property notations; thus, the multiplicity does indeed go next to the property's type.

One way I learned to remember which end has which multiplicity is to imagine a unidirectional graph of instances and write the number next to the arrowheads that point at the target.

BTW, you should use descriptive association end names. These often turn into attribute names in Java, element names in XSD, and so on. For example, in Java, the Mother class might have a "children" attribute of type "Set<Child>". If you don't name them, you'll often get undesirable default names.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top