-
Class Diagrams
Classes
No default visibility in UML.
Associations
Association
Represents connections between objects.
Other decorations can be used, such as labels, which indicate the meaning of the association.
Similarly, a role can be used. Generally, the variable names will match closely with the association roles.
They also help with multiple associations.
Navigability
Note that while two classes can be linked, the two objects are not necessarily referenced to each other.
Two unidirectional associations do not make up a bidirectional association.
For it to be bidirectional, it should be a “cyclical” relationship (the entity points to the other entity which points back to the exact same entity).
Multiplicity
Multiplicity dictates the amount of objects in each association.
The notation is as follows:
where the number of linked objects must be within
Common examples
0..1
can be linked to 0 or 1 object (optional) (by allowing an object to benull
)1
must be linked to 1 object (compulsory)*
can be linked to any amount of objects1..*
must be linked to at least 1 object
Object Diagrams
An object diagram is used to complement class diagrams.
Associations are shown with a line.
An object can be shown as either its class, or its super-class (but NOT both).
No multiplicities as a connection is always to only 1 object.
Notes
UML notes can be used to augment diagrams with more information.
Constraints
This section was marked as optional.
A summary:
Modelling inheritance
Inheritance is modelled with either a filled in/empty triangle arrow head.
Modelling composition
Composition can be modelled with a filled in diamond head.
Modelling aggregation
Aggregation can be modelled with a empty diamond head.
Since the aggregation and composition are similar symbols are similar, it is recommended not to use the aggregation symbol for clarity.
Modelling dependencies
Difference between a dependency and association
A dependency is a need for one class to depend on another without having a direct association in the same direction.
Item
may require aCurrency
object to calculate its price in a specific currency, but it is a transient interaction with no long-term relationship between the objects.An
Modelling enumerations
Enumerations are displayed similar to a class, but with a <<enumeration>>
header, and the area below it is the values of enumeration.
Modelling interfaces
The association is marked with a dotted line and an arrowhead similar to the inheritance.
Modelling abstract classes
An abstract class can be shown by adding a {abstract}
header, or italicising the abstract
methods.
Association Classes
Association classes are often used to store information about an association between two classes.