Examples of State Machines
Here we provide several examples of state machine diagrams:
- Water Phase Diagram as State Machine
- Bank ATM State Machine
- Java EJB - Life Cycle of a Session Object
An example of user account life cycle in the context of online shopping, and shown as UML protocol state machine diagram.
Every company having customers maintains customer accounts and supports a complete life cycle of the account from its creation until it is closed. There are differences in what are the stages (states) in the account's life cycle, and what are conditions or events causing account to change its state.
An example of UML protocol state machine diagram showing thread states and thread life cycle for the Thread class in Java™ 6.
Thread is a lightweight process, the smallest unit of scheduled execution. Instance of the Thread class in Java 6 could be in one of the following states: new, runnable, timed waiting, waiting, blocked, terminated.
Water Phase Diagram
This is example of phase diagram for water represented as UML state machine diagram.
Water can exist in several states - liquid, vapor, solid, and plasma. Several transitions are possible from one state to another. For example, freezing is phase change from liquid state to ice. Condensation is phase change from vapor state to liquid. Water vapor could turn directly into frost through deposition.
State Machine Example - Water Phase Diagram
Bank ATM State Machine
This is an example of UML behavioral state machine diagram showing Bank Automated Teller Machine (ATM) top level state machine.
ATM is initially turned off. After the power is turned on, ATM performs startup action and enters Self Test state. If the test fails, ATM goes into Out of Service state, otherwise there is triggerless transition to the Idle state. In this state ATM waits for customer interaction.
The ATM state changes from Idle to Serving Customer when the customer inserts banking or credit card in the ATM's card reader. On entering the Serving Customer state, the entry action readCard is performed. Note, that transition from Serving Customer state back to the Idle state could be triggered by cancel event as the customer could cancel transaction at any time.
Behavioral state machine example - Bank ATM
Serving Customer state is a composite state with sequential substates Customer Authentication, Selecting Transaction and Transaction. Customer Authentication and Transaction are composite states by themselves which is shown with hidden decomposition indicator icon. Serving Customer state has triggerless transition back to the Idle state after transaction is finished. The state also has exit action ejectCard which releases customer's card on leaving the state, no matter what caused the transition out of the state.
Java EJB - Life Cycle of a Session Object
From the point of view of a local or remote client using the EJB 2.1 and earlier client view API, the life cycle of a session object is illustrated below. A session object does not exist until it is created. When a client creates a session object, the client has a reference to the newly created session object’s component interface.
Java EJB - Life Cycle of a Session Object
