A statechart diagram shows a state machine, focusing on the flow of control from state to state. A state machine is a behavior that specifies the sequences of states an object goes through during its lifetime in response to events, together with its responses to those events.
A statechart diagram is a special kind of diagram and shares the same common properties as do all other diagrams like a name and graphical contents that are a projection into a model. What distinguishes a state chart diagram from other diagrams is its content.
Statechart diagrams commonly contain:
- Simple states and composite states
- Transitions including events and actions
When we model the dynamic aspects of a system, a class or a use case, we will use statechart diagrams in one way:
- To model reactive (event-driven) objects.
Common Modeling Techniques
Modeling Reactive Objects
To model a reactive object:
- Choose the context for the state machine, whether it is a class, a use case or the system as a whole.
- Choose the initial and final states for the object.
- Decide on the stable states of the object. Start with the high-level states of the object and only then consider its possible substates.
- Decide on the meaningful partial ordering of stable states over the lifetime of the object.
- Decide on the events that may trigger a transition from state to state.
- Attach actions to these transitions and/or to these states.
- Consider ways to simplify your machine by using substates, branches, forks, joins and history states.
- Check that all states are reachable under some combination of events.
- Check that no state is a dead end.
- Trace through the state machine, either manually or by using tools, to check it against expected sequences of events and their responses.
Consider the following example: