(Last modified Fri Jun 06 19:11 2008)

home

Software Formalisms
Statecharts

Statecharts are a formalism invented by David Harel in order to address some of the limitations of classical notations for finite state machines (FSMs) in describing complex systems [Harel1987-svfc]. 

An FSM models behavior by presenting states and transitions between them; each transition is associated with an input event to the FSM (or possibly the empty event, in the case of nondeterministic FSMs).  The transitions available from each state correspond to the possible events expected in that situation, and each state represents all the possible histories of events that can lead up to that state. 

Actions can be associated with states and/or transitions.  The FSM can produce a particular action every time a particular state is entered, or exited, or while the FSM is in that state;  and/or the FSM can produce a particular action every time a particular transition is taken.  Actions on states and actions on transitions work equally well, and an FSM with actions on states only can be automatically transformed into an equivalent one with actions on transitions only, and vice versa. 

FSMs have the advantage of conceptual simplicity, computability, and an intuitive diagram form, but the number of states and transitions required to model behaviors increases rapidly as the behaviors become more complex.  This rapid increase is termed state explosion and is a serious disadvantage of FSMs for modelling anything beyond simple behavior. 

Statecharts are a notation that addresses the state explosion problem by adding these features to FSMs: 

The examples below illustrate these features of the notation.  Statecharts are now part of the OMG UML standard (OMG Unified Modeling Language Specification (2003)), from which most of the figures are drawn. 

statechar statechar statechar
"In all airborne states, when yellow handle is pulled seat will be ejected"  (clustering) "gearbox change of state is independent of braking system"  (orthogonality) "display-mode consists of time-display, date-display, and stopwatch-display"  (refinement)

As with any FSM, there are states, transitions between states and the events that cause them, and actions

A state is an equivalence class of paths through the state machine:  it represents all the paths by which you can reach that state.  They have to be equivalent because once you reach that state, there is no record of how you got there, so whatever you do next depends only on that you are there in the state. 

A transition is something that can happen next, once you are in a state.  A transition occurs when its event happens. 

An action is something the state machine makes happen in the world.  Whereas states and transitions are of the state machine, events and actions are of the world.  The events and actions are the ways (the only ways) the state machine interacts with the world it is in.  An action can be attached to a transition, so that it is performed when that transition is taken;  or to a state, so that it is performed when the state is entered, during the state, or when the state is exited (Statecharts use entry/action, do/action, and exit/action to distinguish these). 

An event is something that makes a transition happen.  In Statecharts, an event is written inputEvent[guard]/action, with all three parts optional.  The inputEvent is what happens in the outside world that triggers the transition.  An empty inputEvent means that the transition is taken immediately (if the guard is true at that time).  The guard is a logical formula that filters out inputEvents;  an inputEvent that occurs when its guard is false is ignored, permanently.  An empty guard (the empty string instead of [condition]) represents "true".  The action can be empty (in which case the / is omitted too). 

As with any state machine, you can consider whether you need to add a new state, or combine two states into one. 

statechar
statechar
statechar

This state contains that little symbol (representing two blank states connected by a transition) indicating it is a composite state composed of substates that are not shown. 

statechar
statechar
  • The lower diagram is an abstraction of the upper one, with the internal substates of state "W" suppressed. 
  • The little symbol indicates that substates exist but they are not being shown. 
  • The small vertical bars are stubs serving to terminate transition arrows that connect to internal states.
  • The transitions connected to the internal start pseudostate and final state do not need stubs, as they connect to the superstate.
statechar
statechar statechar
statechar

A synchronization state indicates that concurrent substates may have to pause to synchronize before moving to their following states.  (The "*" in it has some significance but I am not sure what.) 

statechar

References

[Harel1987-svfc]  David Harel.  "Statecharts: A visual formalism for complex systems".  Science of Computer Programming 8[3] pp. 231-274, June 1987.

OMG Unified Modeling Language Specification (2003)

Share-Alike Made with jEdit Valid CSS! Valid HTML 4.01! UC Irvine Thomas A. Alspaugh
Assistant Professor, Informatics Dept.
School of Information and Computer Sciences