tags:

views:

165

answers:

4

Define everything to do when something happens,

I really appreciate that,

but never have tried that yet.

my Q is : How to design a state machine based system?

+1  A: 

'State-event' driven architecture is used in quite a few application domains. In fact, there is a tool called smc (State Machine Compiler) that takes a specification for a state machine (much like lex and yacc take scanner and parser definitions) and generates code in C or other languages to implement it.

ConcernedOfTunbridgeWells
+1  A: 

Have you looked at the State Pattern? Also here. Apache Commons SCXML might also be useful to you.

RichardOD
+1  A: 

The basis of a state machine, in my experience, is the switch statement.

Each case within that represents a state of your machine.

The switch statement needs to be called on a regular basis, this can be within a coded loop, or within an event handler. It really depends on what your state machine is doing, how you want your software to run or react.

You update the state variable from within a case statement in order to change state.

ChrisBD
+1  A: 

Tons and tons of the little buggers.

I suggest that you look up the theoretical basis of finite state machines first and understand for what kind of tasks they are suitable for.

http://en.wikipedia.org/wiki/Finite state machine is a good place to start.

Mart Oruaas