Home CPSC 330

Unified Modelling Language

Overview

UML is a standardized language for documenting software designs. It is at a higher level than code documentation.

There are several reasons to document a design:

UML is an alternative to informal design documentation. There are some advantages of UML:


Class Diagrams

One type of UML diagram is the class diagram. In a class diagram, we depict each class with a rectangle:









The class name is shown at the top, then the attributes of the class, and the methods.

Note that the types are declared in a different syntax than Java and C++ use. UML is separate from any particular programming language.

A - means the field is private, a + means public.

The level of detail is somewhat arbitrary. Sometimes types and protection level are not included. Sometimes only the most important fields are listed.


Connections

In addition to representing the details of a particular class, UML class diagrams can depict the relationships between classes:

For example, the following diagram signifies that the Person class contains a Date object:









This is an example of composition.

The numbers give the multiplicity. One Person has one date.

The following diagram exemplifies dependence. Here, the System class doesn't have a Date object, but it does use it - in the today() method.









Inheritance is shown in the following class diagram which depicts the Person, Student and Employee classes:









Lastly, the following diagram depicts interface implementation:









The fact that the name Polygon is in italics signifies that it is an abstract class (in this case an interface).

Notice that the lines / arrows signify the type of relationship between the classes.


Example: Todo List Program

As a slightly larger example, below is a UML class diagram giving the design of a todo list program:










Example: Course Registration System

Suppose we need to build an online course management system. It should support the following features:

How can we design this system using UML?


Sequence Diagrams

Sequence diagrams show a dynamic interaction between two objects in a system.

For example, this sequence diagram shows how objects in our Todo List program might interact:









Notes:

Sequence diagrams can be made for particular methods or use cases. A use case is a particular way in which the system will be used.


Example: Spell Checker

As another example, consider the task of spell checking a document:









This sequence diagram depicts the call sequence that occurs when a user spell checks a document. This also demonstrates a return in the diagram.


Example: Course Registration System

How could we create sequence diagrams for the following use cases?

State Diagrams

A state diagram can be used to depict the operation of objects which can be in different states. Below is a state diagram for the ghost objects in a Pacman game:







Notes:

Example: Thread States

Below shows different states a thread object could be in. The transitions could be caused by our code, or by the operating system.










Conclusion

UML is used to document different parts of a design.

The usage of UML varies by organization. Some are very rigorous, while others do not use it as much.

Even for an individual, however, it can be a useful tool.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.