Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Sequence models

Sequence models (sequence diagrams) show object interactions over time: who sends what message to whom, when, and under which conditions, using lifelines, messages and combined fragments.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Sequence models (sequence diagrams) are used when an engineer needs to show or reason about the time order of interactions between objects, components or actors. They are essential during application analysis and system design to specify use-case flows, to design object collaborations (class design), and to check that the required message order supports system behaviour before coding.

Key ideas

Start from first principles: software systems are built from objects (entities with state and behaviour). When objects work together they exchange messages in time order. A sequence model records these messages with a visual syntax so engineers can verify interaction logic.

Definitions (each term in bold is defined before it is used):

  • Sequence model: a representation that records the time-ordered interactions between components/objects/actors in a scenario. It focuses on message ordering, not class structure. Use when you need to show how objects collaborate to execute a use case.
  • Sequence diagram: the standard UML visual notation for a sequence model. It depicts participants (objects or actors), lifelines, and messages arranged so that time flows from top to bottom.
  • Participant: an object, instance or actor that takes part in the interaction. In diagrams, participants are shown as a named rectangle (or actor stick-figure for actors) at the top.
  • Lifeline: the dashed vertical line under a participant's box that shows the existence of the participant through time. Time increases down the page.
  • Activation (sometimes called execution specification): a narrow filled rectangle drawn on a lifeline that indicates when the participant is active executing behaviour in response to a message.
  • Message: a directed communication from one participant to another. Messages are drawn as horizontal arrows between lifelines with a label describing the operation or event.
  • Synchronous message: a call where the sender waits for the receiver to finish and return (often shown as a solid line with a filled arrowhead and the receiver shows an activation). The caller is blocked until a return.
  • Asynchronous message: a call where the sender does not wait (often shown with an open arrowhead); the caller continues immediately.
  • Return message: indicates a response value or completion; usually drawn as a dashed arrow back to the caller with an optional label for the return value.
  • Create message: a message that causes the creation (instantiation) of an object; this usually starts the created object's lifeline at the message point.
  • Destroy message: a message that ends a lifeline; the lifeline is terminated with a large X at its end.
  • Interaction fragment: a piece of the sequence diagram that groups messages and conditions, e.g., alternatives or loops.
  • Combined fragment: a box with an operator (such as alt, opt, loop) that defines control flow among interaction operands inside the fragment.
  • Guard: a boolean condition (in square brackets) placed on an operand of a combined fragment that specifies when that operand is executed.

Exact statements and laws commonly required in exams:

  1. Time-order law: In a sequence diagram, vertical position represents time; within a single lifeline, events higher occur before lower ones. Across different lifelines, only the send/receive of messages impose ordering; otherwise events may be concurrent. (Assumption: diagrams are read top-to-bottom.)
  2. Synchronous call semantics: When Participant A sends a synchronous message to Participant B, A is blocked until B returns; therefore activation for B nests inside A's activation. This implies stack-like behaviour similar to a subroutine call.
  3. Asynchronous call semantics: When Participant A sends an asynchronous message to Participant B, A continues immediately and no nesting of activation is implied for waiting; concurrent activations may overlap.
  4. Combined fragment semantics (precise exam form): A combined fragment has an operator and one or more operands. The operator defines how the operands are chosen/executed. Examples:
    • alt (alternative): exactly one operand whose guard is true is executed. If multiple guards are true, UML specifies a nondeterministic choice among them; you may include an [else] operand to cover the case when no guard is true.
    • opt (option): shorthand for alt with one guarded operand; executed only when its guard is true.
    • loop: the operand repeats while its guard condition is true; guards may include loop bounds like [i < n].
    • par (parallel): operands may execute concurrently; ordering is only guaranteed within each operand.
    • break: if the operand's guard is true, its messages execute and then the enclosing interaction is abandoned (subsequent messages outside the fragment do not occur). (Assumptions: UML interpretation; some tool-specific differences exist.)

What to draw and label (exact instructions for exam diagrams):

  • Draw participants as small labeled rectangles across the top, left-to-right in the order you want messages to flow (actor usually at left). For an object use objectName : ClassName (underline if exam expects object notation); for an actor draw a stick figure if required.
  • Under each participant draw a vertical dashed line (the lifeline) down the page.
  • Draw activation boxes (thin vertical rectangles) on lifelines where the participant is performing a task; do not label the activation itself—label the message arrow with the operation name and parameters.
  • Draw messages as horizontal arrows between lifelines. Label each message with the method name and parameters, e.g. authenticate(userId, pwd). For a self-call/recursive call, draw a U-shaped arrow that leaves and re-enters the same lifeline.
  • Use a dashed arrow returning to the caller for return values, with optional label : success.
  • For object creation draw a message arriving at the top of a lifeline where the lifeline begins; for destruction draw an X at the end of the lifeline.
  • For alternatives, draw a large frame around the relevant messages, mark the operator alt in the top-left of the frame, and divide into operands with horizontal lines. Put guards in square brackets: [credentials valid] and [credentials invalid]. You may include an [else] operand for the case when no guard is true.

Notes about assumptions: UML has tool variants; the textual details of arrowheads or exact drawing styles can vary slightly between UML versions and tools. See verify list below for exact items to check.

Formulas

(for sequence models we list the notations and syntax to remember; each line shows the symbol, its meaning and when to use it) participant Name — declare a participant at the top of the diagram; use when you introduce an object or actor. (This is PlantUML syntax; in standard UML you draw a lifeline head box and label it with name[:Class].) objectName : ClassName — label for an instance; use when you want to show a concrete instance rather than just a role. solid line → (filled arrowhead) — synchronous message (caller waits). Use for method calls that block. solid line --> (open arrowhead) — asynchronous message (caller does not wait). Use for events, signals, or messages that do not require an immediate return. dashed line - - -▶ — return message or reply; optionally include return value after :. frame with operator (e.g. alt, opt, loop, par, break) — combined fragment; use to show conditional, repeated, parallel, or early-exit interactions. [guard] — boolean condition for an operand inside a combined fragment; put in square brackets. X at lifeline end — destruction of the object; use when the participant is terminated within the scenario.

(If your instructor requires PlantUML or other tool syntax, adapt the above names to the tool's keywords.)

Worked examples

Example 1 — Login sequence (step-by-step trace). Problem: Draw and explain the sequence of messages for a user login where the system checks credentials and either returns success or failure. Participants: User (actor), LoginController : LoginController, AuthService : AuthService, UserRepo : UserRepository. Steps (explicit trace and what to draw):

  1. User sends submitLogin(username,password) to LoginController. Draw a solid arrow from User's lifeline to LoginController's lifeline; start an activation rectangle on LoginController.
  2. LoginController sends synchronous message verify(username,password) to AuthService. Draw solid arrow to AuthService; show nested activation on AuthService.
  3. AuthService sends synchronous findUser(username) to UserRepo. Draw arrow to UserRepo; show nested activation on UserRepo.
  4. UserRepo returns the User object (draw dashed return to AuthService labelled : user); end UserRepo activation.
  5. AuthService checks password and returns boolean to LoginController (dashed return : true or : false); end AuthService activation.
  6. LoginController uses a combined fragment alt with two operands separated by a horizontal line (stacked vertically): first operand with guard [return = true]: send createSession(user) to AuthService and return 200 OK to User; second operand with guard [return = false]: return 401 Unauthorized to User.
  7. If success, AuthService creates a Session object (draw create message arriving at a new lifeline Session starting where message arrives) and a return message back to LoginController. Final answer (in words): show the diagram with activation nesting and a labelled alt fragment for success/failure. Bold conclusion: LoginController blocks on AuthService synchronously, and the alt fragment shows two possible return flows.

Example 2 — Order processing with loop and create/destroy. Problem: Buyer places an order with multiple items; system processes each item, generates invoice and destroys temporary Cart. Participants: Buyer, OrderController:OrderController, InventoryService, Invoice : Invoice (created), Cart : Cart (destroyed after processing). Trace:

  1. Buyer → OrderController: placeOrder(orderRequest) (synchronous).
  2. OrderController starts activation and sends for each item in orderRequest.items — model this as a loop fragment with guard [for each item].
  3. Inside loop: checkStock(item) synchronous to InventoryService → InventoryService returns : available or : outOfStock.
  4. If available, OrderController adds to invoice (create Invoice when first available item processed — show create message to start Invoice lifeline) and continues.
  5. After loop ends, OrderController sends finalizeInvoice() to Invoice and receives : invoiceId (dashed return).
  6. Finally, OrderController sends destroy to Cart (draw X at end of Cart lifeline) and returns : orderConfirmed to Buyer. Final answer: show the loop frame labeled loop with guard like [i = 0..n-1], show create for Invoice on first use, and show X for Cart destroyed at end.

Common mistakes

  • Drawing time left-to-right instead of top-to-bottom. Remember: top is earlier, bottom is later.
  • Wrong arrow types: using synchronous arrow for asynchronous behaviour and vice versa — this changes blocking semantics.
  • Forgetting activation boxes: omit nested activations when a synchronous call should show nested execution.
  • Misplacing combined fragments: not enclosing the correct messages or failing to put guards on operands.
  • Showing multiple returns as solid lines instead of dashed return arrows.
  • Starting a lifeline from the top when the object is created later — if an object is created in the scenario, its lifeline must start where it is created.

For your exam

Kinds of questions:

  • Definitions and short notes (define lifeline, activation, message types, combined fragment operators).
  • Draw a sequence diagram for a given use case and explain steps.
  • Convert a sequence diagram to a narrative or to pseudo-code showing call order.
  • Explain the difference between synchronous and asynchronous messages with an example.
  • Show the use of alt/opt/loop fragments in a specified scenario.

What full-marks answers include:

  • Clear labelling of participants at the top and correct lifelines down the page.
  • Correct arrow types and message labels (include parameters and return values where relevant).
  • Activation boxes where participants execute, nested for synchronous calls.
  • Proper use of combined fragments with operator and guards written in square brackets.
  • Show object creation and destruction correctly (lifeline start at create, X at destroy).
  • Short textual explanation of the message flow and why chosen operators/arrows were used.

Quick check

  1. What does a solid arrow with a filled arrowhead usually mean in a sequence diagram?
  2. Where should activation rectangles appear for a synchronous call? Draw in words.
  3. How do you show a repeated interaction over a collection of items in a sequence diagram?

Answers: 1) A synchronous call (caller waits). 2) On the receiver's lifeline, nested under the message arrival and inside the caller's activation if caller is blocked. 3) Use a loop combined fragment with a guard (e.g. [for each item] or [i < n]).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?