What is a state machine diagram?
A state machine diagram, or state diagram, shows the states an object can be in and the events that move it from one state to another. It is part of UML, where it is called a state machine diagram, and is based on finite-state machines and Harel statecharts.
Read it from the filled start circle. Rounded boxes are states, arrows are transitions labeled with the event that triggers them, and a ringed circle marks the end.
When to use a state machine diagram
- Use it to define a lifecycle, such as content moving from draft to review, approved and published.
- Use it before coding order, payment or ticket statuses, to catch impossible or missing transitions.
- If the focus is the sequence of steps people take rather than the states of one thing, use a flowchart.
How to make a good state machine diagram
- Name states as conditions ("In review") and transitions as events ("submit", "reject").
- Check that every state has a way out, unless it is a final state.
- Add guard conditions in brackets when the same event can lead to different states.
- Keep one diagram per object; do not mix the states of an order and a payment.