State diagrams: choice and fork pseudostates
简介 / Introduction
State machines describe how an object transitions through a set of discrete states during its lifecycle. Two important pseudostates power most real-world models:
- choice — conditional branching, like
if/else, selecting the next state based on guard conditions. - fork — parallel branching, splitting a single flow into multiple concurrent paths.
This post uses the same scenario (order processing) to demonstrate both PlantUML and Mermaid, then compares them head-to-head.
PlantUML 版
1 | @startuml |
PlantUML uses <<fork>> and <<join>> stereotypes to mark fork and join pseudostates on the diagram; multiple arrows then branch out from the fork.
Mermaid 版
1 | stateDiagram-v2 |
Mermaid uses Fork and Join as special state nodes to achieve the same effect, with guards written inline on the transition lines.
对比 / Side-by-side
| Feature | PlantUML | Mermaid |
|---|---|---|
| Choice pseudostate | state X <<choice>> |
guards inline on transitions (cond) |
| Fork syntax | <<fork>> + <<join>> |
Fork / Join nodes |
| Parallel arrows | multiple --> from fork |
multiple paths from Fork node |
| Style | class/activity-diagram like | concise YAML-like syntax |
小结 / Wrap-up
choice and fork are the two core pseudostates in state machine modeling. PlantUML implements them via <<choice>>, <<fork>>, and <<join>> stereotypes — semantically precise but more verbose. Mermaid uses built-in Fork/Join nodes — much shorter but lacks an explicit choice pseudostate (guards are inline only). Pick based on whether you need semantic precision or syntactic brevity.
- Title: State diagrams: choice and fork pseudostates
- Author: puml.online
- Created at : 2026-09-06 09:00:00
- Updated at : 2026-09-07 01:06:15
- Link: https://puml.online/blog/state-diagram-choice-fork-en/
- License: This work is licensed under CC BY-NC-SA 4.0.