I would like to create a state machine.
State would have its
run method, and, according to some logic would then set a next state.
- Option 1:
If each state is responsible for determining a next state, then it would have a
next_state() which would return a pointer or an id of some other state, thus forcing each state to know about the existence of other states ==> bad.
- Option 2:
If some other entity is responsible for the next state, then some logic there would have to calculate the next state, but would depend on current state, thus breaking the current state's encapsulation (or force the creation of a getter-like method, that would in reality be option 1) ==> bad
So, I can't come up with a way that doesn't break encapsulation for the part of a state machine that decide the next step.
I would like to hear the best practice in this case, as even Wikipedia doesn't shed light on this.