gordon.is.a.moron@gmail.com wrote:
Quote:
>
Hello,
>
I'm implementing a State Pattern in C++, based on the example in the
GoF book. However the example they give only shows a single transition
to another state. In my program I have a choice of states depending on
the input. So, I was going to give each concrete State a small Map of
inputs to States and then find out what transition to make.
>
However I was wondering if this is a sort of mix between State Table
and State Pattern, but surely you need some conditional code in the
concrete state to decide what state to go to? It just seems that the
State Pattern is designed to eliminate this, yet there is still a need
for it when deciding which state to change to when you have a choice
of multiple state transitions.
>
Regards,
Gordy
>
I don't think the state pattern says anything about how you manage
transitions. It's about how you represent states, namely each state is a
class, and therefore all logic pertaining to that class is in one place
(including its transitions to other states). As you say, you need some
conditional code somewhere.
BTW, this has nothing much to do with C++ so is off-topic here. Try an
OO design group. (comp.objects maybe, not sure).