UML Multiplicity
![](https://yuml.me/collard/uml-multiplicity-project-names.svg)
UML Multiplicity Categories
|
Mandatory |
Optional |
Single Value |
[1] |
[0..1] |
Multivalued |
[1..*] [2..4] |
[*] [0..*] [0..2] |
Mandatory & Optional Multivalued
Optional Single Value
![](https://yuml.me/collard/uml-multiplicity-optional-huge.svg)
Optional Single Value: C++ Pointer
![](https://yuml.me/collard/uml-multiplicity-optional-normal.svg)
Solution: Flag
- For each optional, have to maintain another flag variable
- Have to remember the relationship between
name
and hasName
- C++17 feature, similar to
boost::optional
- Can be used on any value type (non-pointer)
- Allows for lazy loading/allocation
- Complete replacement of having to use pointers for optional single-value attributes
Use Case: Represent Optional Types
Takeaway
- Use
std::optional
where you are mapping from an Optional type in UML
- Use
std::optional
in all cases where pointers are used to represent optional values