State Machine Diagram
State Machine Diagram
A State Machine Diagram( in UML ) is a graphical representation of a system that describes the different states it can be in and how it transitions between those states. Each state represents a particular condition, and transitions occur based on specific events or conditions.
This diagram to model the dynamic behavior of an object in response to external or internal events:
- It shows the states of an object.
- It represents transitions between states.
- It focuses on how an object changes its state based on events and conditions.
State machine diagrams are widely used in computer science, software engineering, and automation to model the behavior of systems such as printers, vending machines, and traffic lights.
State Machine Diagram for a Printer
A printer operates in different states such as being idle, printing, switched on, switched off, or out of paper. The state transitions occur based on user actions like turning the printer on or off, sending a print command, completing a print job, or running out of paper.
State Machine Diagram
stateDiagram-v2 [*] --> Switched_Off Switched_Off --> Switched_On : Power On Switched_On --> Idle : Ready Idle --> Printing : Print Command Printing --> Idle : Print Completed Printing --> Out_of_Paper : Paper Depleted Out_of_Paper --> Idle : Paper Refilled Switched_On --> Switched_Off : Power Off
Printer States
Some of the printer states are as follows:
- Switched Off: The printer is powered off and not functioning.
- Switched On: The printer is turned on and ready to operate.
- Idle: The printer is on but not currently printing.
- Printing: The printer is actively processing and printing a document.
- Out of Paper: The printer has run out of paper and cannot continue printing until paper is refilled.
State Transitions
The main state transitions of the printer are as follows:
- Power On: Transitions the printer from ‘Switched Off’ to ‘Switched On.’
- Ready: Moves the printer from ‘Switched On’ to ‘Idle’ state.
- Print Command: When a user sends a print job, the state changes from ‘Idle’ to ‘Printing.’
- Print Completed: After printing, the printer goes back to the ‘Idle’ state.
- Paper Depleted: If the printer runs out of paper while printing, it transitions to ‘Out of Paper.’
- Paper Refilled: When new paper is loaded, the printer returns to the ‘Idle’ state.
- Power Off: Turns off the printer, transitioning it back to ‘Switched Off.’