Finally, the current state variable or stack is updated to re?¬‚ect the new
current state.
In the Watch example, the states and button events were represented simply as
Strings and the transition tables were Hashtables. It is also possible to make State
objects, whose contents will then closely re?¬‚ect the properties of the State objects in
the model. In a procedural language implementation we could move in the opposite
direction, and use integers to represent states, with arrays replacing the Java
Hashtables. While an attempt to write a generic state machine in C would have
problems with such an approach because the size of the arrays could not be known, in
our case the number of states in each model is known at generation time. By judicious
use of enum variables, the implementation could thus be simultaneously easy to read,
fast to execute, and small in code size.
The transition guard condition and the various actions are of course rather harder to
map into data. Important here is to remember that in the models, these should not be
represented as code fragments, but as domain concepts and actions. One useful
approach is that for every kind of action, there is a corresponding modeling language
concept??”an object, role or relationship, depending on how the state machine is
294 GENERATOR DEFINITION
modeled.
Pages:
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547