Finite State Machines (FSM) – State Diagrams, UML, States, Transitions & Events
This article explains finite state machines with exam questions and tags.
In a Nutshell
A finite state machine models system behavior through defined states and transitions between them, triggered by events or conditions.
Technical Definition
A finite state machine (FSM) represents a system with a fixed number of states. State transitions are triggered by events, conditions, or inputs. Each state represents a specific system configuration. Transitions often include actions executed during the change. Visualization typically uses state diagrams following UML notation. FSMs appear in control logic, UI development, network protocols, and embedded systems. They help structure complex behavior in a clear, traceable way.
Exam-Relevant Points
- States, transitions, and actions form the core elements
- Triggers define when a transition occurs
- UML state diagrams visualize behavior precisely
- Exam questions often ask for creation or interpretation of such diagrams
- Practical examples: traffic light control, login workflows, game states
- Security aspect: states prevent unwanted transitions
- Business benefit: reduces errors through clearly defined processes
- Documentation: state diagrams belong in software design documentation
Core Components
- State
- Initial state
- Final state
- Event
- Guard condition
- Action
- Transition
- State diagram
- State validation for error prevention
- Testing through state sequence simulation
Practical Example
// Example: Traffic light control
State: Red
Event: Timer expires
Action: Switch to Green
New state: Green
Explanation: The traffic light changes state based on a time event. The action is the change in light color.
Advantages and Disadvantages
Advantages
- Clear process flow
- Easy to test
- Structured error handling
Disadvantages
- Complexity grows with many states
- High modeling effort
Typical Exam Questions (with Short Answers)
- What is a finite state machine? A model representing systems with a finite number of states and defined transitions.
- What triggers a state transition? An event and optionally a condition.
- How are FSMs represented in UML? Using state diagrams.
- What typically belongs to a transition? An event, a condition (optional), and an action.
- How is the initial state shown in a diagram? As a filled black circle.
- Are FSMs relevant for security? Yes, they prevent unwanted or unexpected state changes.
- Practical applications of FSMs? In control systems, such as elevators, vending machines, and games.
Key Sources
- UML State Diagrams Explained
- https://en.wikipedia.org/wiki/Finite-state_machine
- PlantUML Documentation



