2

I'm learning about UML, but I am confused about the concept of multiplicity. Consider the Customer class and Order class, in this diagram:

enter image description here

  • First: which class does the number 1 belong to? what about the 0..*?
  • Second: 1 on the line up, 0..* on the line down, Are there strict restrictions?
  • Third: how to read the relation between Customer class and Order class?
Christophe
  • 68,716
  • 7
  • 72
  • 138
John Xue
  • 21
  • 1
  • 3

1 Answers1

2

The number 1 is a shortcut for 1..1, which means at least one and at most one, so in summary, exactly 1.

In the context of your diagram, it means that that for every instance of Order on the other side, there is exactly 1 "associated" Customer instance (the correct term should be "linked" since a link is to an association what an object is to a class).

A multiplicity of 1..5 would mean at least 1 and at most 5.

The 0..* multiplicity, which can also be noted with the shortcut *, means at least 0 (i.e there can be none) and no upper limit (i.e there can be a huge number of associated instances). So for every Customer instance, there may be none, one, or many more linked Order instances.

This shall answer your first point, as well as your last point. You need to define "strict restrictions", as this is not an UML term.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • A very good answer. One point I would change: The official name for the thing in between instances is "link". Everybody will understand what you mean, but some will be confused, because they just learned that _classes_ are associated. Also you use _"every instance"_ and _"any instance"_. I know, both are synonyms, but people might wonder, whether there is a difference. I prefer "every". – Axel Scheithauer Jul 13 '23 at 07:54
  • Two more additions for the OP's benefit. While the extended notation `1..1` is absolutely correct it is almost never seen in such form, pretty much always shown in the simplified version `1`. Of course the number can be anything, so whenever there is just one number `n` it means "the lower and upper bounds are the same and they equal n. Now the second thing worth knowing is that `0..*` (meaning the lower bound is 0 and there is no upper bound) can be shortened to just `*`. In this case it is important to stay consistent across the diagram (i.e. don't mix both contracted and extended notation) – Ister Jul 13 '23 at 11:29
  • @AxelScheithauer Thanks for your suggestions. I edited accordingly. I always hesitate to use "link" as it is a less known term, which might confuse the category of people that is complementary to the one to which you refer. Moreover, I wonder if there may not also be links which are not instances of an association. But I found a way to avoid the confusion. – Christophe Jul 13 '23 at 18:14
  • @Ister Thank you for your insight. I decomposed 1 into 1..1 just to jump to the more easily to the general case. I edited as suggested to draw attention on the potential * shortcut. – Christophe Jul 13 '23 at 18:18
  • @Christophe thanks for you help, about the Second question, i mean, first i saw the class `Customer ` and `Order `. because 1 is near by `Customer`.so i thought 1 `Customer` can have 1(this 1 is the 1 on the top of the link) `Order`. but this is unreasonable. In reality, 1 Customer could have 0 or more Orders. so why 1 is near by `Customer`, rather then 0..* – John Xue Jul 14 '23 at 07:54
  • @JohnXue Exactly. Interestingly, most of the modelling notations follow the same logic of UML called "look-across". Only very few (and now obsolete) notations use the same-side logic that you first thought about. – Christophe Jul 14 '23 at 16:06
  • About the term *link*: The UML says that objects are linked, when they somehow can interact. The rules for links can be specified with associations or connectors or both. Also a parameter of a behavior would mean, that there is a link while the behavior is executing. The real system can of course have additional links, that have not been intended. Representing a single link by a model element is only possible, if it is specified by an association. This is unfortunate, since this might be the reason, why people tend to think that links are always instances of associations. – Axel Scheithauer Jul 14 '23 at 18:35