As we saw in the Watch example in Chapter 9, each model can map to a new
subclass of a state machine class. The state machine class provides a variable to hold a
table that maps each state to the transitions for that state, and the subclass constructor
?¬?lls in that variable for this model. The Watch example also had other tables that
mapped states to their decompositions, display functions, and blinking information,
but these would often be better represented in similar variables in individual State
objects. The information recorded for each state and transition is thus domainspeci
?¬?c, in contrast with the not infrequent writings proposing ???the ultimate state
machine implementation in Java/C/Snobol.???
While the details vary, the main task of the state machine superclass is to receive
events and push them through the state machine. It has a variable for the current
state, or possibly a stack if state history is to be implemented. Looking up the
current state in the transition table returns a table that maps events to transitions. If
the event received is in that table, the transition it points to is considered for
evaluation. Any condition on the transition is evaluated, and if that passes, the
current state??™s exit action, the transition action, and the new state??™s entry action are
performed.
Pages:
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546