UML

Learning Objectives

Pre-requisites

Lesson

Software development is inherently complex. Many high profile software systems have failed. Complexity is down to a number of factors including the fact that:

Our job as software engineers is not to dive straight into coding but to journey through the whole Software Development Lifecycle (SDLC), analysing requirements, producing designs and then developing a fully-tested, robust and maintainable system.

The history of Object-Oriented Analysis and Design

Object-Oriented Analysis and Design (OOAD) emerged as a software methodology in the 1990s and is still very much in use today. OOAD focusses on breaking down a system into a collection of objects with clear roles and responsibilities, which collaborate to achieve some higher level behaviour.

"The only way to write complex software that won’t fall on its face is ... to build it out of simple parts" — Eric S. Raymond

OOAD uses the Unified Modelling Language (UML) notation to express object and interactions in a diagrammatic form.

Object Oriented Analysis

Object Oriented Analysis has 2 main purposes:

Let's consider objects within an Airport domain.

Our 2 passenger objects share common properties, for example, each has a name, passport number and seat number. We can therefore declare a Passenger "Class" which is a blueprint for creating instances such as Passenger Bob. We can do the same for our other objects and create "Bag", "Plane", "CrewMember" and "Airport" classes. We model these classes in a UML Class diagram.

basic class diagram showing classes in the Airport domain

A UML Class diagram models the objects that make up the system and the relationships between them

The functional requirements for our system can be represented in UML Use Case diagram notation. Use Cases document the names of scenarios that give value to a user (Actor). Actors represent the roles that people and other systems play when they interact with the system under development.

Airport domain Use Cases

A UML Use Case describes a function that a system performs to achieve a user’s goal.

Object Oriented Design

Object Oriented Design has the following purposes:

The UML Class Diagrams created during the analysis phase can be refined with additional behaviour/relationships and can translate into actual software classes and objects when you write code.

detailed class diagram showing relationships between classes in the Airport domain

Note that we can use specific notation to illustrate different types of relationships such as:

TypeRepresentationMeaning
InheritanceinheritanceRepresents a "is a type of" relationship e.g. a Passenger is a type of Person
AssociationassociationA general relationship between 2 classes (arrow indicates direction)
AggregationaggregationRepresents a "part of" relationship e.g. an Engine is part of a Plane
CompositioncompositionA special type of aggregation where one class is destroyed when the the other class is destroyed e.g. an Airport has Terminals (the Terminals are destroyed if the Airport is destroyed)

Sequence diagrams

Sequence diagrams help us illustrate how classes in our system interact with each other to implement the Use Cases described in the analysis phase. Sequence diagrams help us define the behaviour (methods) that each class needs and allows us to consider how exception conditions will be handled.

sequence diagram for drop bag use case

A UML Sequence diagram illustrates the sequence of messages between objects for a particular Use Case

The UML also includes other diagrams such as Activity, Component, Package and Deployment however we will not cover these in this lesson.

Assignment

Create UML Use Case, Class and Sequence diagrams to model a customer's interactions with a bank's ATM.

Assignment extension task

Investigate the difference between Object Oriented and Functional programming.

Additional resources