Activity models
Activity models (UML activity diagrams) show control and data flow of behaviours—useful for modelling workflows, algorithms, and concurrent processes in system design.
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
Activity models (UML Activity Diagrams) are used to describe the step-by-step flow of control and data in a use case, an algorithm, or a business process. Engineers use them when analysing requirements, designing component behaviour, or communicating concurrency and synchronization to developers and testers.
Key ideas
Start with behaviour. A behaviour is something the system does. In UML activity modelling we show behaviour with a flow of tokens between processing steps.
- Activity: A high-level behaviour composed of smaller steps. Think of an Activity as a container for a workflow (e.g., "Place Order").
- Action: The smallest unit of executable behaviour inside an Activity (e.g., "Validate card"). An Action executes when it receives a token.
- Token: An abstract unit of control or data that moves along edges. Tokens represent the permission to execute and possibly carry data. Tokens may originate at an Initial node or be produced by Actions; Fork nodes duplicate tokens. Tokens are consumed by Actions, Flow final nodes, or an Activity final (which also removes remaining tokens).
- Control flow: A directed edge that moves control tokens from one node to another (drawn as a plain arrow). Control tokens carry no data, only control.
- Object flow: A directed edge that moves object tokens (data) between Actions or Object nodes. Object flows may show the object name or type beside the arrow.
- Initial node: The start point of control tokens for an Activity (draw as a filled circle). It produces tokens when the activity starts.
- Activity final node: Stops the entire Activity, removing all tokens and terminating execution (drawn as a bullseye: a filled circle inside a hollow circle). When reached, all flows stop.
- Flow final node: Terminates the flow on incoming edges but does not stop the whole Activity; other tokens elsewhere continue.
- Decision node: A control node that routes a single incoming token to exactly one outgoing edge based on guards (draw as a diamond). A Decision can also be used on object flows; decisions do not duplicate tokens.
- Merge node: A control node that brings together alternative flows (draw as a diamond). A Merge simply forwards a token from any incoming edge to the single outgoing.
- Fork node: Splits a single incoming token into concurrent tokens on multiple outgoing edges (draw as a thick bar). The fork duplicates tokens (one copy to each outgoing flow) so parallel Actions can run.
- Join node: Synchronizes concurrent flows. A Join waits for tokens on all incoming edges and produces one token on the outgoing edge (draw as a thick bar). This enforces synchronization.
- Object node: A place that holds object tokens (temporary storage in the flow). It models buffers, parameters and returns. Object nodes have optional multiplicity and an upper bound (capacity).
- Pin: An input or output pin on an Action; pins show where objects come into action and where they flow out. Activity parameter nodes represent the inputs and outputs of the Activity at its boundary; use them to show parameters instead of generic object nodes.
- Swimlane / Partition: A vertical or horizontal partition that groups Actions by the responsible actor, component or object (e.g., "Payment Service"). Swimlanes show allocation of responsibility.
- Guard: A boolean condition written in square brackets on an outgoing edge of a Decision node, e.g., [valid == true]. If no guard evaluates true, no edge is taken; the token is not consumed and execution may deadlock unless a default [else] edge exists.
- Interruptible activity region: A region of the activity where an interrupting edge can stop contained flows on some event (draw as a dashed rounded rectangle). Structured activity nodes such as LoopNode and ConditionalNode provide explicit constructs for loops and conditionals and may be used instead of back-edges in exams.
- Signal and Accept event actions: Used for asynchronous communication — a SendSignalAction sends a signal; an AcceptEventAction waits for a signal.
Assumptions and semantics commonly tested in exams (state step-by-step):
- An Activity starts by placing one control token on the Initial node’s single outgoing edge (use a Fork after it to start concurrency).
- An Action can start (become enabled) when all required incoming tokens (control or object tokens on required pins) are available; it consumes them and produces tokens on its outgoing edges.
- At a Decision node, a single incoming token is consumed; exactly one outgoing edge with a true guard is selected and the token continues on that edge.
- At a Fork, the single incoming token is duplicated: one token placed on each outgoing edge (so concurrency begins).
- At a Join, tokens arriving on all incoming edges are required: the Join consumes all and produces one token on the outgoing edge (synchronization end).
- Object nodes hold tokens; when capacity is limited they may block producing Actions until space exists.
What to draw (diagram instructions exam-style):
- Draw a rounded rectangle and title it with the Activity name.
- Place a filled circle for the Initial node and put an outgoing arrow to the first Action; if you need multiple concurrent starts, add a Fork after the Initial node.
- Draw Actions as rounded rectangles (or small rectangles with names like "ValidateCard()"), connect with arrows for Control flow; label object flows with objectName:Type.
- Use diamonds for Decision/Merge and thick bars for Fork/Join. Label guards beside the decision outgoing edges in square brackets (e.g., [ok], [error]).
- Show swimlanes as vertical bands; place Actions inside lanes to indicate responsibility.
- Mark Activity final node as a bullseye (a small filled circle inside a hollow circle). Mark Flow final as a small circle with an X.
Relation to other models: Activity diagrams model behaviour across objects and components similar to Use case models (what the system does) and Sequence models (who sends what messages, chronological), and complement State models (how an object changes with events). Use Activity for workflows and algorithms; use State for lifecycle of an object; use Sequence for message exchange details.
Formulas
[guard] — guard expression syntax. [guard] is a boolean condition that must evaluate true for that outgoing edge to be taken. No SI units (boolean). Applies at Decision nodes.
DecisionNode: consumes 1 token -> produces 1 token — Decision consumes one incoming token and routes to exactly one outgoing edge. No units. Applies to decision nodes.
MergeNode: consumes 1 token from any incoming -> produces 1 token — Merge forwards a token from any incoming edge. Applies at Merge nodes.
ForkNode: consumes 1 token -> produces N tokens (1 per outgoing) — Fork duplicates the incoming token to all outgoing edges; N is outgoing-edge count. Applies at Fork nodes.
JoinNode: consumes N tokens (one per incoming) -> produces 1 token — Join synchronizes: waits till all incoming tokens present, then continues. N is incoming-edge count.
InitialNode: produces 1 control token on its single outgoing edge — When the Activity starts; use a Fork after it to create parallel tokens. Applies at Activity start.
ActivityFinal: consumes all tokens -> terminates Activity — Activity final removes all tokens and stops execution of this Activity.
ObjectFlow: objectName:Type — Notation for labelling object flow with object name and type next to the arrow.
(These are notation and token rules, not physical formulae. There are no SI units.)
Worked examples
Example 1 — Login flow (single-threaded). Question: Draw an activity diagram for "Login": user enters credentials, system validates; if valid go to home, else show error and allow retry twice, then lock account. Model answer (diagram description and token flow):
- Draw Initial node; arrow to Action "EnterCredentials" placed in lane "User".
- Arrow to Action "ValidateCredentials" in lane "AuthService". From this Action draw a Decision node with two outgoing edges:
- Edge labelled [valid] -> Action "ShowHome" -> ActivityFinal.
- Edge labelled [invalid] -> Action "IncrementRetryCount" -> Decision node testing [count < 2] and [count >= 2].
- If [count < 2] -> Action "ShowError" -> back to "EnterCredentials" (loop). If [count >= 2] -> Action "LockAccount" -> ActivityFinal.
- Explain token flow: Initial node emits one token into EnterCredentials; each Action consumes and produces one token; loops return token to EnterCredentials until retry condition fails. A full-mark answer draws nodes, guards, swimlanes, and explains how token returns create the retry loop.
Example 2 — Producer-consumer with buffer (concurrency). Question: Model two concurrent producers and one consumer sharing a buffer of capacity 2. Model answer (diagram description and token flow):
- Draw Initial node, arrow to Fork node (thick bar) that has three outgoing edges: Producer1, Producer2, and Consumer Actions (these represent concurrent threads). Place these Actions in appropriate swimlanes (e.g., "Producer Service" and "Consumer Service").
- Between producers and consumer, draw an Object node named "Buffer:Queue<Item>" with capacity note "{upperBound=2}".
- Producers: Action "ProduceItem" outputs to Object flow into Buffer (use output pin named out:Item). Consumer: Action "ConsumeItem" has input from Buffer.
- Fork duplicates the initial token to allow the three Actions to execute concurrently. Producers add object tokens to Buffer; if Buffer has two items, producers block (capacity full). Consumer removes tokens from Buffer when available.
- Join can be used later to synchronize completion: add a Join bar that waits for both producers and consumer to finish and then go to ActivityFinal. Explain synchronization: Fork duplicates tokens to start concurrent threads; Join requires token from all concurrent paths.
Example 3 — Mapping a Use Case to an Activity Diagram (theory model answer). Question: How do you convert a Use Case description into an Activity diagram? Model answer steps:
- Identify the main success scenario and alternate flows from the Use Case.
- Each step becomes an Action in the Activity; flows between steps become Control or Object flows.
- Represent alternatives with Decision/Merge nodes and concurrency with Fork/Join.
- Place Actions in Swimlanes for actors listed in the Use Case. A full answer shows a small example (e.g., "Pay by card" use case) with decision for [card valid], and explains token movement.
Common mistakes
- Thinking a Decision creates tokens or splits the flow into multiple concurrent threads.
- Not labelling guards on Decision outgoing edges or forgetting a default edge.
- Using Activity final when they meant Flow final — Activity final kills all threads (tokens) in the Activity.
- Missing swimlanes: forgetting to show who performs each Action.
- Drawing arrows backward (always show direction of token flow; arrows should be clear).
- Ignoring object node capacity and blocking semantics for buffers in concurrency examples.
For your exam
Typical question types:
- Definitions and short notes (define Action, Fork, Token, difference between Flow-final and Activity-final).
- Draw and label an activity diagram from a textual scenario (workflow, algorithm, concurrency).
- Explain token semantics in a given diagram (trace tokens step-by-step).
- Convert a Use Case to an Activity diagram or compare Activity to State or Sequence diagrams. What a full-marks answer includes:
- Clear drawing with Initial node, Actions, Control/Object flows, Decision/Merge and Fork/Join where appropriate, Final nodes, and Swimlanes if actors/components are involved.
- Guards on Decision edges and labels on Object flows where data matters.
- A short token-trace describing how tokens move, where concurrency starts and ends, and what nodes consume or produce tokens.
- Mention of relevant semantics (e.g., Fork duplicates tokens, Join waits for all incoming, Activity-final terminates all flows).
Quick check
Q1. What does a Fork node do to tokens? Q2. How does a Join node decide to produce its outgoing token? Q3. Which node would you use to stop the whole activity immediately?
Answers: Q1: Duplicates the incoming token to each outgoing edge. Q2: It waits until a token is present on every incoming edge, then consumes them and produces one outgoing token. Q3: Activity final node (it removes all tokens and terminates the Activity).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?