Search Knowledge

© 2026 LIBREUNI PROJECT

UML Design / Behavioral Modeling

State Machine Diagrams

State Machine Diagrams

While Activity Diagrams show the flow of a process, State Machine Diagrams (or Statecharts) show the lifecycle of a single object as it transitions between states in response to events.

1. Key Components

  • State: A rounded rectangle representing a stable condition of an object (e.g., Idle, Pending, Processing).
  • Transition: An arrow from one state to another.
  • Event (Trigger): The occurrence that causes a transition (e.g., buttonClicked, timeout).
  • Guard: A boolean condition [condition] that must be true for the transition to occur.
  • Action: An operation / action() performed during the transition.

2. Transition Syntax

Event [Guard] / Action

3. Example: Document Lifecycle

PlantUML Code:

[*] --> Draft
Draft --> Submitted : submit()
Submitted --> Published : approve() [isUserAdmin]
Submitted --> Draft : reject()
Published --> Archived : archive()
Archived --> [*]
System Diagram
DraftSubmittedPublishedArchivedsubmit()reject()approve() [isUserAdmin]archive()

4. Implementation Tip

State machines are often implemented in code using the State Design Pattern, where each state is a class, or a simple switch-case if the logic is simple.