Multiplicity
General
In UML, multiplicity describes how many instances of one class can be connected to an instance of another class through a given association. This relation is often expressed as a string showing the lower and upper bounds at the endpoints of a connection.
Let's look at an example from a hypothetical banking system. In our system, each customer must have at least one account at our bank and should not have more than five accounts in total. We could model this with the following UML association:
The text 1 .. 5
placed at the connection's end defines the range of possible accounts. To interpret this diagram, we would start reading from left to right :
One customer must have between one and five bank accounts
(note that the cardinality of the customer - "one" - is not explicitly modeled in the diagram)
But that's not all: We can also describe the relation between bank accounts and customers. Let's say that every account must belong to at least one customer, but for joint accounts, it could also have two owners:
Here we had to place the lower and upper bound on the other end, and consequently, we must now read from right to left:
One bank account must belong to one up to two customers*.
Again, the diagram does not contain the cardinality of "one" for the bank account.
Finally, we can combine both multiplicities into the same diagram to express both directions:
It's essential to keep in mind that this diagram combines the two expressions mentioned above into a single diagram, so the correct way to read it would be:
One customer has one to five bank accounts and one bank account belongs to one or two customers.
and not, as one would intuitively think
One or two customers have one to five bank accounts.
Multiplicity in UMLBoard
1.4
UMLBoard supports the definition of multiplicities for all associations (i.e., compositions, aggregations, and simple associations). By default, a newly created relationship does not have any multiplicity information stored, indicated by the grayed-out text none when moving the mouse over a connection.
1.13: Usage relations now also support multiplicity. This is especially helpful if you want to add additional text to the start/end of such a connection.
Start Editing
To add a multiplicity to a connection, click and hold (or double-click) on one of the none
texts. The cardinality editor will open with the cursor always starting on the edit field for the lower bound.
Just enter any cardinality you want; UMLBoard does not set you any restrictions here. You can use any number or arbitrary string as input. If you only want to set a single boundary, you can also leave one cardinality edit field empty. Clearing both edit fields will remove the multiplicity from this end.
Navigation
After entering any boundary, you have the following options:
- Pressing Enter will immediately confirm your input and close the editor.
- Pressing Tab instead will move the cursor to the following edit field:
- If you are in a lower bound editor, it moves to the next upper bound
- If you are in the upper bound editor, the cursor will move to the next (the target) multiplicity.
- If you are already at the upper bound of the target multiplicity, this has no effect.
- Pressing Shift+Tab will move the cursor back to the previous multiplicity border. Using this shortcut, you can also switch back from the target to the source multiplicity.
- Pressing Esc will cancel your edit process and revert all values you entered since the editor opened.
Context Menu
1.6
Starting with Version 1.6, you can also edit cardinalities by right-clicking on a relation's end point and choosing the Edit context menu entry.
Additional Notes
- UMLBoard implements the following shortcuts from the UML Specification:
- if lower and upper bound are the same, they will be written as a single value, so
1 .. 1
becomes just1
. - A multiplicity with a lower bound of 0 and an upper bound of * (unspecified) becomes just
*
instead of0 .. *
.
- if lower and upper bound are the same, they will be written as a single value, so
- Currently, UMLBoard does not do any validity checks on the multiplicity, so you can enter anything you like. Therefore, something like
a .. b
ormin .. max
is very well possible. - Multiplicities in property syntax (like:
wheels: Wheel [4]
) are not yet supported but will be available in later versions. Please also remember that you will lose an association's multiplicity when you convert it into a property and back.
Tip
While it's not the intended use case, the multiplicity can also be used to display a source/target description for your association's ends. Just enter the text in the lower bound and keep the upper bound empty. As already mentioned, the multiplicity values are not validated, so you're free to enter anything you like here.