The Unified Modeling Language (UML)

These notes are the "bigger picture" of UML: the when and why to use the different kinds of diagrams. The "how" is explained in the "Readings" listed for each diagram type below.

Overview

UML is a diagramming standard for diagrams to aid the design process There are many different types of diagrams, some more and some less critical.

Classes of UML diagrams

Different Perspectives from which to use Diagrams

UML diagrams can be used at all levels of design, and their use is subtly different at each level:

Conceptual (part of requirements capture)
To understand the underlying domain; no need to think about the relation to the resulting software. Domain models (discussed later) are a conceptual model. Conceptual models are a good place to start design from.
Specification (part of initial design)
Looking at the entities in the diagrams as specifications for what the code should do (interfaces), not the actual code (implementation). Most often the perspective you want to use.
Implementation (part of coding)
The actual implementation.
To diagram implementations effectively you must focus on key attribs/operations or the pictures get too big.

Class diagrams

Readings: Fowler Chapters 3 and 5; HFOOA&D pp.577,3,180-185,206-207; Ambler

Class diagrams are the most useful kind of UML diagram. Once you have understood the basics here are some usage suggestions.

Making Good Class Diagrams

Avoid making diagrams that have too much information in them -- Put in everything that matters for the problem you are solving with the diagram, and no more.

Associations

Naming roles

Attributes

Interfaces

Abstract classes

To indicate a class is abstract, add the constraint {abstract}.

Aggregation and composition

Use-case Diagrams

Readings: Fowler Chapter 9, HFOOA&D pp.296-297; Ambler

Sequence Diagrams

Readings: Fowler Ch. 4, HFOOA&D p.567; Ambler

Activity Diagrams

Readings: Fowler Ch. 11; Ambler

Package, Component and deployment diagrams

Readings: Fowler Chapter 7,8,14; Ambler Package; Ambler Component; Ambler Deployment

Object Diagrams

Readings: Fowler Ch. 6; Ambler

These diagrams are very simple, they just show a snapshot of the object heap at runtime.

Communication Diagrams

Readings: Fowler Ch 12; Ambler

State Machine Diagrams

Readings: Fowler Ch. 10; HFOOA&D p.568-569; Ambler, Ambler style guide

State diagrams are just fancy finite automata: each node is a different state, and edges indicate dynamic transitions from state to state.

When to use state diagrams?

State structure can be an important dimension of some designs