Suggested Workflow
Using state modeling in a program requires a different way of thinking about the problem. Here are a few suggestions that may be helpful when incorporating state behavior into a program.
- Avoid the "one large state model" design. The power of state machines is when they interact by generating events to each other. Keep the state models relatively small. Break the program behavior down into components that interact by generating events. Think of a state model as adding lifecycle behavior to an entity like a class in the program.
- Draw a graphic at the beginning. Even if you abandon it later, state modelling requires some up-front thinking and thinking about state models in two dimensions is much easier than in a linear sequence as will be required when it is coded. The transcoding to a moore package model is very straight forward. Use the drawing ability of the package to insure that what is actually implemented is truly what was intended.
- Use the tracing capability during debugging. Obtaining a chronological sequence of event dispatch and transition is critical to understanding what is going on. Since the flow of control sequencing is factored away from the code base in a state machine design, tracing is the way to obtain the time ordering of processing that tells the run-time story.