Finite State Machines (FSM) – State Diagram, UML, States, Transitions & Events
This post is a glossary entry on finite state machines – including exam questions and tags.
In a Nutshell
A finite state machine describes the behavior of a system through defined states and transitions between them, triggered by events or conditions.
Compact Technical Description
A finite state machine (FSM) models a system with a finite number of states. State transitions are triggered by triggers such as events, conditions, or inputs. Each state represents a defined system configuration. Transitions often contain actions that are executed during the change. The graphical representation typically occurs as a state diagram according to UML notation. Finite state machines are used in control logic, UI development, network protocols, and embedded systems. They help to model complex behavior in a structured and comprehensible manner.
Exam-Relevant Key Points
- States, transitions, and actions as central elements
- Define triggers that determine when a transition occurs
- UML state diagrams visualize the behavior precisely
- IHK exams often ask about creating or interpreting such diagrams
- In practice, e.g., in traffic light controls, login workflows, game states
- Security aspect: States help to prevent invalid transitions
- Economically: Reduces misbehavior through clearly defined procedures
- Documentation requirement: State diagram as part of software design
Core Components
- State
- Initial state
- Final state
- Event
- Condition (Guard)
- Action
- Transition
- State diagram
- State validation for error prevention
- Testing through simulation of state sequences
Practical Example
// Example: Traffic light control
State: Red
Event: Timer expired
Action: Switch to Green
New state: Green
Explanation: The traffic light changes state based on a time event. The action is the change of light color.
Advantages and Disadvantages
Advantages
- Clarity in processes
- Good testability
- Structured error handling
Disadvantages
- Complexity can increase with many states
- High modeling effort
Typical Exam Questions (with Brief Answer)
- Finite state machine? Model for representing systems with a finite number of states and defined transitions.
- State transition triggered by? Event and possibly a condition.
- UML representation for finite state machines? State diagram.
- Typically belongs to a transition? Event, condition (optional), action.
- Initial state represented in diagram? As a filled black circle.
- Finite state machines security-relevant? Prevent invalid or unforeseen state changes.
- Practical application of FSMs? In control systems, e.g., elevators, vending machines, games.
Most Important Sources
- UML state diagrams explained
- https://en.wikipedia.org/wiki/Finite-state_machine
- PlantUML Documentation