Unit 6: Sequence Diagrams
Learning Objectives
- Identify objects, lifelines, activation bars, and messages in a sequence diagram
- Distinguish between synchronous, asynchronous, and return messages
- Align a sequence diagram with the class diagram and use cases it models
Core Input
Read through each tab before working through the key concepts.
A sequence diagram has four core elements:
-
Object / Participant — drawn as a labelled box at the top of the diagram.
Named as
objectName : ClassNameor just: ClassName. Objects are the actors and system objects involved in the interaction. - Lifeline — a vertical dashed line extending downward from each object. Represents the object's existence over the duration of the interaction. Time flows downward along lifelines.
- Activation bar — a narrow rectangle on a lifeline. Shows the period during which an object is actively processing — executing an operation or waiting for a return.
- Return message — a dashed arrow pointing back to the caller. Represents the completion of a called operation, optionally labelled with a return value.
Messages are the arrows that connect lifelines. Three types matter most:
- Synchronous message — drawn as a solid arrow with a filled arrowhead. The sender waits for the receiver to finish processing before continuing. This is the most common type — it represents a normal method call.
- Asynchronous message — drawn as a solid arrow with an open arrowhead. The sender does not wait — it continues processing immediately after sending. Used for event-driven systems, message queues, or background tasks.
- Return message — drawn as a dashed arrow, usually with an open arrowhead. Represents the reply from a synchronous call. Often labelled with the return value. In simple diagrams it is sometimes omitted if the return is obvious.
Messages are labelled with the operation name and any parameters:
enrol(course), findUser(userId).
Combined fragments are rectangular frames drawn around part of a sequence diagram to indicate conditional or repeated logic. The operator label appears in the top-left corner.
- alt — alternative flows (like if/else). Contains multiple operands separated by dashed lines, each with a guard condition in square brackets. Only one operand executes.
- opt — optional flow (like an if without else). The enclosed messages occur only if the guard condition is true.
- loop — repeated execution. A guard condition specifies when the loop continues or stops.
- par — parallel execution. Each operand represents a concurrent flow.
Combined fragments are useful for capturing decision logic without needing to draw a separate activity diagram. Use them sparingly — a very complex sequence diagram usually means the design is overly complicated.
Key Concepts: Diagram Elements
Work through each item. Sequence diagrams use precise notation — the details matter.
Both appear as boxes at the top of the diagram, but they represent different things:
- Actor — the external user or system that initiates the interaction. The same actor from your use case diagram. Often drawn as a stick figure rather than a box to distinguish it visually.
-
Object — an instance of a class in your class diagram. Named as
name : ClassName. This is the software object receiving and sending messages.
A key consistency check: every class name appearing in a sequence diagram should exist in your class diagram. If it does not, your class diagram is incomplete.
A lifeline is the dashed vertical line below each participant's box. It represents that object's existence over time during the interaction.
Time flows downward. Messages higher on the diagram happen earlier than messages lower down. This makes the sequence diagram a readable narrative: read it top to bottom to follow the flow of the interaction.
An object can be created during an interaction — shown by the message arrow pointing to the object box itself, rather than to the lifeline below it. An object can also be destroyed — shown by a large X at the end of its lifeline.
An activation bar (also called an execution specification) is a narrow rectangle drawn on a lifeline. It shows the period during which an object is actively executing.
The bar starts when the object receives a call and ends when:
- It returns a response to the caller (end of synchronous call)
- It finishes processing an asynchronous message
Activation bars can be nested — a bar within a bar shows that an object calls itself (recursion) or that a new call arrives while it is still processing a previous one.
In simple diagrams, activation bars are sometimes omitted. Include them when the timing and duration of processing is important to communicate.
Time flows strictly top to bottom. A message drawn higher on the diagram occurs before one drawn lower. This imposes a clear ordering on the interaction.
However, sequence diagrams do not specify exact timings or durations — only ordering. They show what happens before what, not how long each step takes.
This is an important limitation: if you need to model timing constraints (e.g. a response must arrive within 500ms), a timing diagram is the appropriate UML diagram, not a sequence diagram.
Key Concepts: Messages and Fragments
Getting message types right is critical for reading and producing accurate sequence diagrams.
A synchronous message is drawn as a solid arrow with a filled arrowhead. It means: the sending object calls the receiving object and waits for the response before doing anything else.
This is the standard model for most software interactions — a method call where the caller blocks until the method returns. The sender's activation bar extends downward until the return message arrives.
Example: LoginController calls UserDatabase.findUser(userId) and waits for the User object to be returned before proceeding.
An asynchronous message is drawn as a solid arrow with an open (stick) arrowhead. The sender does not wait for a response — it continues processing immediately.
Use this for:
- Sending events or notifications (fire and forget)
- Interactions with message queues or event buses
- Background thread processing
- User interface interactions (button press triggers event, UI does not block)
Asynchronous messages do not have a corresponding return arrow — there is no response the sender is waiting for.
A return message is drawn as a dashed arrow pointing back to the original caller. It represents the response from a synchronous call.
When to include it:
- When the return value is important to the logic of the diagram
- When the interaction would be ambiguous without it
- In detailed, precise diagrams where completeness matters
When it is acceptable to omit it:
- When the return is obvious and labelling it adds no information
- In overview diagrams where clarity of the high-level flow matters more than completeness
An alt fragment (alternative) is drawn as a rectangular frame around part
of the interaction, with the label alt in the top-left corner.
Inside, two or more regions are separated by dashed lines.
Each region has a guard condition in square brackets: [condition].
Only the region whose guard condition is true will execute — exactly like an if/else statement.
Example:
- Region 1:
[password matches]→ create session, return success - Region 2:
[password does not match]→ return failure message
The opt fragment is similar but has only one region — the enclosed messages occur only if the guard is true (no else branch).
A loop fragment is drawn as a rectangular frame labelled loop.
The guard condition specifies the condition under which the loop continues.
Often written as loop(minOccurrences, maxOccurrences) or with a condition:
loop [more items in cart].
Use loop fragments when the same sub-interaction repeats — for example, processing each item in a shopping cart, or retrying a failed connection up to three times.
Caution: Heavy use of combined fragments can make a sequence diagram hard to read. If the logic becomes complex, consider whether an activity diagram would communicate the same information more clearly.
Watch
Video coming soon
Check Your Understanding
Select the best answer for each question.
In a sequence diagram, what does a vertical dashed line represent?
A solid arrow with a filled arrowhead in a sequence diagram indicates:
Activities
Individual task
Choose one use case from your shared diagram (Unit 3) and model it as a sequence diagram. A good choice is a login or booking flow with a clear sequence of steps.
Your diagram must include:
- At least three participants (one actor + two or more classes from your class diagram)
- At least four messages, correctly labelled with operation names
- At least one return message
- Activation bars on each object during processing
Pair task
Exchange sequence diagrams and check the following:
- Class consistency: Does every class name in the sequence diagram exist in the shared class diagram from Units 4–5? List any that are missing.
- Message logic: Does the order of messages make sense? Is there any step that seems to be missing or in the wrong position?
- Message types: Are synchronous and asynchronous messages used correctly? Are return messages included where they are needed?
Group task
Compare all individual sequence diagrams for the same use case.
- Where do the diagrams differ? Are any differences due to design choices or modelling errors?
- Identify any classes that appear in a sequence diagram but are missing from the shared class diagram. Add them to the class diagram now.
- Agree on a single shared sequence diagram for this use case. It will be used in Unit 8 as part of the integrated model.
Review
- Object / Participant box — the actor or class instance at the top
- Lifeline — dashed vertical line representing the object's existence over time
- Activation bar — narrow rectangle showing active processing
- Synchronous message — solid arrow, filled arrowhead (sender waits)
- Asynchronous message — solid arrow, open arrowhead (sender continues)
- Return message — dashed arrow back to caller
- Combined fragments — frames for alt, opt, loop, par logic
A sequence diagram shows objects of classes interacting. If a class appears in a sequence diagram but not in the class diagram, the structural model is incomplete — there is no specification of what that class contains or how it relates to others.
Consistency between diagrams is not just good practice — it is a requirement for the models to be usable by a development team. In Unit 8 we will examine this integration systematically.
Proceed to Unit 7: Activity Diagrams when ready.