• Class Diagrams

Classes

Class namevisibility name: type = default valuevisibility name (param list): return typemethodsattributes+: public-: private#: protected~: package privateunderlines denote class-level attributes/methods

No default visibility in UML.

Associations

Association

Represents connections between objects.

BookPersonauthorShow as line:BookPersonShow as attribute:author: PersonShow as line or attribute, not bothPREFERRED


Other decorations can be used, such as labels, which indicate the meaning of the association.

BookPersonwritten byBookPersonwritesTwo ways of writing labels:Person writes bookBook written by person


Similarly, a role can be used. Generally, the variable names will match closely with the association roles.

ManWomanhusbandwife

They also help with multiple associations. ManWomanwifegirlfriend


Navigability

Note that while two classes can be linked, the two objects are not necessarily referenced to each other.

CatPersonownerCatPersonbreederpetpettwo unidirectionalassociationsa bidirectionalassociationCatPersona unidirectionalassociation

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 to inclusive.

Common examples

  • 0..1 can be linked to 0 or 1 object (optional) (by allowing an object to be null)
  • 1 must be linked to 1 object (compulsory)
  • * can be linked to any amount of objects
  • 1..* must be linked to at least 1 object

ClubPlayers*1A player only has 1 clubA club has many playersTutorStudentHead Tutor11..4011..511..8A student has 1 tutorA head tutor has upto 5 tutors andmust have at least 1 tutorA tutor has 1 head tutorA student has 1 head tutorA tutor has up to 8 studentsand must have at least 1 studentA head tutor has up to 40 studentsand must have at least 1.

Object Diagrams

An object diagram is used to complement class diagrams.

instance: Classattribute = valueno methods showninstance: Classcan omit attributes:Classcan omit object name(unnamed instance)

Associations are shown with a line.

zai: PersonleftHand: ItemrightHand: Item

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.

melovelifeMay not exist:Work in progress.Note with associationNote withoutassociation

Constraints

This section was marked as optional.

A summary: constraints summary

Modelling inheritance

VehicleCarVehicleCarboth acceptable

Inheritance is modelled with either a filled in/empty triangle arrow head.

Modelling composition

CarWheel

Composition can be modelled with a filled in diamond head.

Modelling aggregation

constraints 1 1

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 a Currency object to calculate its price in a specific currency, but it is a transient interaction with no long-term relationship between the objects.

An

constraints 1 1 1

Modelling enumerations

Enumerations are displayed similar to a class, but with a <<enumeration>> header, and the area below it is the values of enumeration.

Vehiclestatus: Status<<enumeration>>StatusBROKENSEMI-BROKENWORKING

Modelling interfaces

Vehicle{interface}Sellable

The association is marked with a dotted line and an arrowhead similar to the inheritance.

Modelling abstract classes

constraints 1 1 1 1 2

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.

Class 1Class 2AssociationClass