(Last modified Tue May 27 15:30 2008)

home teaching teaching schedule site map

In4matx 115
Software Specification and
Quality Engineering
Spring 2008
Statechart examples

Actions on transitions

Figure 1 shows a statechart describing one direction of a stoplight that has corresponding walk lights and no turn signals.  The length of time it is green is controlled by an external signal, as is the length of time the "walk" light is on while the stoplight is red (and thus the total time it is red).  All of the actions are on the transitions. 

The external signals are "turnYellow" and "flash".  All other transitions are triggered after specific amounts of time:  Yellow to Red after long enough for cars approaching the intersection to stop, and Walk to Flashing after long enough to ensure pedestrians can cross completely. 

Actions on transitions

Figure 2 shows a corresponding statechart whose actions are on the transitions. 

Stoplight statechart

Figure 1.  Stoplight, actions on transitions

Stoplight statechart

Figure 2.  Stoplight, (most) actions in states

The next steps

The next step is to validate the statecharts, by writing up some stoplight scenarios and walking through the statechart to make sure they are possible (if they are positive scenarios) or not possible (if they are negative scenarios describing what should not happen);  and analyzing the statechart (manually or with one of the available tools) to gain appropriate confidence that the statechart describes a stoplight doing everything it should and not doing anything it shouldn't. 

Statecharts for two directions (North-South, and East-West) could be combined too, with each direction's Green and Yellow running concurrently with the other direction's Walk, Flashing, and Don't Walk;  the Yellow and Don't Walk state transitions would need to synchronize so that they end at the same time. 

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