COMP433 · Software Engineering · Chapter 4

UML: Use Case & Activity Diagrams

Read the requirements, then build each diagram, step by step, with every part traceable to where it came from.

Move with the arrow keys or the buttons below. Slides with a builder have their own Next / Play controls.

Where these diagrams come from

UML is a notation, not a method: it fixes the shapes; you decide which diagram to draw and when. In analysis, once requirements are elicited, two behavioural views are drawn first, in order, and each is read out of the one before it.

Requirementselicited + analysedUse case diagramwho + whatUse case descriptionthe contractActivity diagramthe flow

UML at a glance

14 diagram types, 9 standard, in two groups:

  • Structure (static): use case, class, object, component, deployment
  • Behaviour (dynamic): activity, sequence, communication, state

This chapter

  • The use case diagram: who uses the system and what they can do.
  • The use case description: the contract behind each ellipse.
  • The activity diagram: the flow of a non-trivial use case.

History in one line: UML was unified at Rational by Booch, Rumbaugh and Jacobson and standardised by the OMG in 1997.

Part 1 · Use case diagrams

The first model in analysis: who uses the system and what they can do. We build it from the requirements, then detail and refine it.

The diagram

  • What it is, and when to draw it
  • Actors, and how to find them (users, external systems, time)
  • Use cases, and how to find them (noun-verb analysis)
  • Building blocks and the system boundary

Refining and detailing

  • <<include>>, <<extend>>, generalisation, extension points
  • Composite (multi-level) use cases
  • The use case description, the contract behind the ellipse
  • Scenarios: normal, alternative, error
Goal

Read a narrative and draw a correct, fully-refined use case diagram, then write the description and scenarios behind it.

Use case diagrams: what and when

A use case diagram is usually the first model in analysis. On a single page it shows the system's actors and the tasks they perform with it, so stakeholders can confirm scope before any design.

It serves three decisions

  • Scope: is this the right set of tasks?
  • Actor inventory: who and what interacts with the system.
  • Task index: each use case points to its description, an activity diagram, a sequence diagram.

What it does not show

  • The order of steps inside a use case (activity diagram).
  • The messages between objects (sequence diagram).
  • The data, or where the system runs.

Use case building blocks

Four symbols. Actors sit outside the boundary; use cases (verb-named ellipses) sit inside; a plain line is an association, with no arrowhead because participation is undirected.

Actora role, a person or an external system, that uses the system; drawn outside the boundaryUse casea task the system provides, named with a verb; drawn inside the boundarySystem boundaryseparates what is inside the system from the actors outside itAssociationlinks an actor to a use case it takes part in; a plain line, no arrowhead
Key

A plain association has no arrowhead. A verb-phrase ellipse is a use case; a noun is a class, not a use case.

Finding the actors

Read the requirements and ask four questions; each answer is an actor.

  • Which roles do the direct users play?
  • Who provides information to the system?
  • Who receives information from it?
  • Which external systems must it communicate with?

Primary actor

A role (usually human) that starts a use case for its own goal: Guest, Librarian, Doctor.

Secondary actor

An external system the system depends on and calls out to: payment provider, email or SMS service, verification service.

Key

Primary actor starts a use case for its own goal; secondary actor is the external system the system calls out to.

An actor is a role, not a person; the same person can be two actors. Name each actor with a noun. Not every use case is started by a person: time or another system can trigger one (a temporal / clock actor, e.g. a nightly report or a scheduled message).

Finding the use cases

Two complementary techniques, then a quick check.

Scenario-based

Write the system's processes as scenarios; each interaction with the system is a candidate use case.

Actor-based

For each actor, ask what they need from the system, and what else they take part in for someone else's benefit.

Noun-verb analysis ties it to the text: in the requirements, nouns and roles become actors, verbs become use cases, and the noun-verb pairings become associations. Name every use case with a verb, "Borrow book", not "Book borrowing".

Key

Name every use case with a verb. Nouns become actors; verbs become use cases.

Building a use case diagram, from the requirements

Built one element at a time, with each actor and use case traced back to the narrative and the user requirement it came from. Use the builder's Next / Play.

Relationships: include, extend, generalisation

RelationshipMeaningArrow (dashed unless noted)
<<include>>The base use case always performs the included sub-task. Factor it out to avoid repetition.base → included
<<extend>>An optional / conditional behaviour that fires only when a guard at an extension point holds.extension → base
generalisationOne use case (or actor) is a more specific kind of another and inherits it.solid line, hollow triangle, specific → general
Key · direction

<<include>> points base → included (always performed); <<extend>> points extension → base (conditional). They go opposite ways. The tail sits on the case that "knows about" the other.

The remaining use case notations

Actor generalisation, use-case generalisation, composite (multi-level) use cases, and extension points, each on a small example with a note on when to use it.

Composite use cases: drilling down a level

When one ellipse really stands for several tasks, draw it as a composite use case (the small grid marker) at the top level and expand it in a lower-level diagram. A deep system can add a 2nd level under a 1st-level composite, exactly how Adel decomposes Manage patient registration.

Top levelManagerManage roominventoryexpands to1st level: Manage room inventoryAdd roomUpdate rateSet availabilityRemove roomManager
Key

The grid marker says "described by its own diagram". Use it to keep the top level readable; do not hide weak analysis behind it, every sub-use-case must still be a real, verb-named task.

Use case descriptions

The ellipse is the index; the description is the contract the team builds against, the full template: pre-conditions, trigger, the main flow, and the alternative / exception flows. Worked example for a Library use case:

TitleBorrow copy of a book
ActorsBookBorrower (primary), Librarian (primary)
Pre-conditions1. Borrower is a member. 2. Borrower is below the loan limit.
TriggerBorrower asks the Librarian to borrow a copy.
Main flow1. System checks the allowance. 2. Record the loan and compute the due date. 3. Issue the copy (status → on-loan).
Alternative / exception1a. Limit reached: the loan is refused and the flow ends. 3a. Barcode unreadable: the Librarian records the problem; no copy is issued.
Post-conditionsOn success: loan recorded, copy on-loan, loan count incremented. On failure: nothing changes.
Key · the connection

The main flow and each alternative / exception are the same paths you write as scenarios (next slide) and draw as the decision branches and loops of the activity diagram. One description, three consistent views.

Scenarios

A scenario is one specific path through a use case, with no branching. Each non-trivial use case gets at least three:

The three kinds

  • Normal: the happy path that succeeds.
  • Alternative: a different but successful path.
  • Error: an unsuccessful outcome with explicit handling.

Example: Borrow a book

  • Normal: Joe (no books out) borrows a copy; it is issued.
  • Alternative: Joe uses the self-service kiosk instead of the desk.
  • Error: Joe already has six books out; the loan is refused.
Key

A scenario has no branching: "if X else Y" is two scenarios, not one.

Part 2 · Activity diagrams

Where the use case diagram says what, the activity diagram says how it flows: the order of work, the decisions, the parallel steps, and who does each. We learn the notation, then build one from a use case.

The notation

  • Initial / final nodes, and actions
  • Decision / merge and fork / join, and how each pair must close
  • Swimlanes (hand-offs) and loops (repeat / retry)

Putting it together

  • From a use case description to a flow
  • Two granularities: one use case, or a whole business process
  • A second worked domain, end to end
Goal

Take one use case and draw a well-formed flow: decisions closed by merges, forks by joins, every path reaching a final node.

Activity diagrams: what and when

An activity diagram unpacks how one use case flows: the order of work, the decisions that branch it, the steps that run in parallel, and which actor performs each. It answers: what happens, in what order, and who does it.

  • Draw one when a use case has real decisions, parallelism, or several actors, not for a simple linear path.
  • One activity diagram per use case is the usual granularity, but a higher-level one can model a whole business process spanning several use cases (next slide).
  • It is also an elicitation tool: it surfaces use cases and steps the static view missed.

Activity notation

A small, fixed vocabulary. Two pairs are easy to confuse: a decision picks one branch while a fork runs all; a merge re-joins a choice while a join waits for parallel flows.

Initial nodewhere the flow starts (exactly one)Final nodewhere a path ends (there may be several)Actiona unit of work, named with a verb phraseDecision / Mergesplit on a guard (one branch runs) / re-join the alternativesFork / Joinstart parallel flows / wait for every flow to finishSwimlaneassign each action to an actor or system
Key

Decision = exactly one branch runs (a choice). Fork = all branches run (concurrency). This is the most common confusion.

Swimlanes, loops, and a well-formed flow

Swimlanes

Columns that assign each action to an actor or system. An arrow that crosses a lane boundary is a hand-off of responsibility, often where bugs hide.

Loops

Repeat (do the next item), retry (a check failed, correct and try again), and guarded exit / timeout (leave after a limit). Each is a decision that points back into the flow.

Key · they must close

Every decision is closed by a matching merge and every fork by a matching join; an opening diamond or bar with no closing one is the most common ill-formed-flow error. And every path must reach a final node, the flow must not get "stuck".

Activity notations: parallel work and choices

Fork and join for steps that run at once; decision and merge for a choice. The pairing is the point: a fork is always closed by a join, and a decision by a merge. Step through the builder and watch each pair open and then close.

From a use case to an activity diagram

Now apply all of it. The Book room use case, unpacked into a flow: each step of its description lights up as the matching action appears; the description's alternative flows become the diagram's decision branches and loops, and swimlanes assign each step to the Guest, the system, or the external provider.

The other granularity: a whole business process

An activity diagram is not limited to one use case. At the business-process level it composes several use cases into a single flow. Here Book a journey runs three reservations in parallel, each its own use case, with a retry loop on the car.

Choose trip datesReserve flightReserve hotelReserve carcaravailable?[no][yes]Confirm trip
Key

Same notation, wider scope. Pick one granularity per diagram: a single use case, or a whole process, not both. The process view often drops swimlanes, the focus is order and concurrency.

A second domain, end to end: the Help Desk

The same method on a fresh scenario, both diagrams. This one also shows actor generalisation (a Senior Agent is a kind of Support Agent).

Common pitfalls

  • Include vs extend direction. The base points to its include; the extension points to its base. They go opposite ways.
  • Decision vs fork. A decision picks one guarded branch; a fork starts all of them. Choose deliberately.
  • Unbalanced control. Every decision needs a matching merge; every fork a matching join.
  • Missing boundary. Without the system boundary you lose what is in versus out, and which actors are external.
  • Noun-named use cases. "Book borrowing" is a class, not a use case; name it with a verb.
  • Over-modelling. Do not draw an activity diagram for a trivial linear flow, and do not factor an include used by only one base.

How to create them

Use case diagram

  1. From the requirements, the people, roles and outside systems become actors.
  2. The tasks they need become use cases (verb-named).
  3. Draw the boundary; connect actors to use cases with associations.
  4. Factor shared steps as <<include>>; optional ones as <<extend>>; specialise with generalisation.
  5. Write a description and scenarios for each.

Activity diagram

  1. Pick a use case with a non-trivial flow; take its description.
  2. Lay out swimlanes for the participants.
  3. Start at the initial node; add actions in order.
  4. Branch with decisions (close with merges); run parallel work with forks (close with joins); loop where steps repeat or retry.
  5. End every path at a final node; check the flow never gets stuck.

Both come straight from the requirements: that traceability is the point of drawing them.