Sequence Diagrams
Sequence diagrams are interaction diagrams that show how objects operate with one another and in what order. They are time-centric, showing the chronological sequence of messages.
1. Key Components
- Lifelines: Represented by vertical dashed lines. They represent the existence of an object over time.
- Activations/Execution Bars: Thin rectangles on the lifeline showing when an object is actively processing a request.
- Actors: Stick figures representing external entities (users, other systems).
2. Message Types
The arrow heads matter significantly:
| Symbol | Message Type | Description |
|---|---|---|
-> | Synchronous | Caller waits for a response before continuing. (Full arrowhead) |
->> | Asynchronous | Caller continues without waiting for response. (Open arrowhead) |
--> | Return | Response sent back to the caller. (Dashed line) |
-> (to self) | Self-Message | A method call within the same object. |
3. Combined Fragments (Logic Control)
Sequence diagrams use “fragments” to handle logic:
alt(Alternative): If/else logic. Only one branch executes.opt(Optional): If then. Executes only if condition is true.loop(Iteration): Repeats a sequence of messages.par(Parallel): Messages that happen concurrently.
4. Detailed Example
PlantUML Code:
actor User
participant "Web UI" as UI
participant "Auth Service" as Auth
database DB
User -> UI: Enter Credentials
UI -> Auth: login(user, pass)
activate Auth
Auth -> DB: findUser(user)
activate DB
DB --> Auth: userPayload
deactivate DB
alt #LightGreen credentials valid
Auth --> UI: token
UI --> User: Dashboard
else #Pink invalid
Auth --> UI: error 401
UI --> User: Show error message
end
deactivate Auth
System Diagram
Conceptual Check