How does one go about getting the number of elements in a class's attribute that has 0..* multiplicity?
I can only think of either using an << iterate>> construct to do so but that seems silly or a counter whenever something is added. This seems inelegant if not inefficient.
If you want to refer to the cardinality of an attribute in an activity diagram, you can use the size()
function. Example:
If your activity diagram is meant to be read by humans, not by machines, you can also just simply write "number of elements in object.attr".
If you want to access the cardinality in order to create a loop, you might prefer the expansion region. An iterate construct in activity diagrams can be achieved by using an expansion region with mode = iterative. Suppose class Order
has attribute orderline
of type OrderLine[1..*]
. The following diagram shows how to iterate over all orderlines.
See section 16.12 of the UML 2.5.1 specification for more information.