I am trying to understand UML class diagrams.
Imagine two classes that are related with each other by association. What is the difference between {ordered}
and {sequence}
for the association?
-
1Hint: Software Engineering Stack Exchange... expect research before askinggnat– gnat2019年03月05日 16:24:36 +00:00Commented Mar 5, 2019 at 16:24
-
Welcome on SE ! Your question is indeed very interesting and there's little clear info about this topic. Even in the UML specs. Maybe you could add a diagram to illustrate your question ?Christophe– Christophe2019年03月05日 21:12:37 +00:00Commented Mar 5, 2019 at 21:12
1 Answer 1
In short
{sequence}
means {ordered, nonunique}
In long
Your question addresses indeed a very subtle difference in the UML semantics associated to multiplicity:
ordered
means that the objets are ordered in the collection of associated elements. This means that there is a mapping between a positive integer to the elements in the collection. It doesn't say more, and in particular, it doesn't say if the elements in the associated collection areunique
or not.sequence
orseq
means that the association implements an ordered bag, that is an ordered collection of elements where the same elements may occur several times (example: a trip made of a sequence of towns : New-York -> Chicago -> New-York -> Los-Angeles -> New-York ).
And longer
In an UML model, association-ends have two possible properties: isOrdered
and isUnique
. The ordered
implies that isOrdered = true
(explicitely specified). For sequence
, you can deduce from the text that it's isOrdered = true
and isUnique
= false
.
Table 7.1 of the UML 2.5.1 specification shows the following relationship:
isOrdered isUnique Type of collection
false true Set
true false OrderedSet
false true Bag
true false Sequence
But the UML specifications do not explain much about the type of collection. I think that it is a concept which main purpose is to align the UML on the OCL semantics (OCL being the language that can be used to formally describe the constraints in UML). I don't see a clear advantage in terms of expressivity of the model itself.
Furthermore, the specifications uses its own terminology inconsistently, since the text body explicitly says that the sequence means an ordered bag.
Therefore I'd advise to avoid the {sequence}
and prefer {ordered
, nonunique
} instead, which is unambiguous and language neutral.
-
2You have made an error in copying the table. a
Bag
should be a non-unique collection and anOrderedSet
is a unique collection.Bart van Ingen Schenau– Bart van Ingen Schenau2019年03月06日 07:54:43 +00:00Commented Mar 6, 2019 at 7:54
Explore related questions
See similar questions with these tags.