[LC++]State Machines

Jack Lloyd lloyd at acm.jhu.edu
Thu Dec 13 06:07:04 UTC 2001


If you have access to a copy of Design Patterns, check out the "State"
and "Interpreter" models. The State pattern does almost exactly what you're
suggesting. Also the Flyweight pattern to reduce memory usage would
probably come in very handy.

I would say it's an interesing idea that could be fairly practical. -J

On Mon, 10 Dec 2001, Paul M Foster wrote:

> I'm just playing with some ideas here, and looking for feedback. Anyone
> ever heard of doing a state machine as a set of classes, with each state
> as a separate class? I'm thinking about parsing a file containing
> keywords and parameters. (Yes, I know you can use lex and yacc for this;
> I'm just kicking around ideas.)
>
> I haven't fleshed this out fully in my mind, but there might be a base
> class that has a get_next_token() method. Each class inherits from the
> base class and handles a specific state. The state class object would
> process whatever it needed to, and then have a next() method that called
> the get_next_token() method, interpreted the token, and determined what
> the next state would be, etc.
>
> Is this a really horrible idea? Intriguing?
>
> Paul
>
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
>




More information about the tuxCPProgramming mailing list