Behind the Curtain

SMC is so straight forward and easy to use, that it is unnecessary to know anything about the code it generates in order to use it. But for the curious, here is an explanation.

The SMC-generated code follows the State pattern as described in Gamma, Helm, Johnson and Vlissides "Design Patterns" book (pp. 305 to 313):

State Pattern

The SMC State pattern is different due to support for multiple machines, a default state, default transition and push/pop transitions:

SMC State Pattern

SMC deviates from the State pattern as follows:

While SMC generates many classes, they take up little run time space. There is only one instance of each concrete state class. Only one <AppClass>Context class need be instantiated for each <AppClass> class instance.

Finally, the SMC State pattern is hidden from the application class. All a developer needs to do is instantiate <AppClass>Context, passing to it the <AppClass> object. After that, it's only a matter of calling the Context object's transition methods.

For further examples on using the State Machine Compiler, see Section 6: For Example ... .