When you stumble over situations like described in #8 you might want to try to find the solution that scales and promises to be versatile. In exchange, you discard some overrated elegance like seen in #9 and trade it for a bit of verbosity.
Welcome to the strategy pattern!
_This way of using the strategy pattern is also known as State pattern_
With this pattern, you end up with one dedicated class per automata state.
By modeling it that way you can now benefit from all features that classes have e.g.:
This allows feeding information from one state to the other by just calling the constructor of the new state and telling the machinery that this is the new state. (not possible with #9)
It allows for implementing additional interfaces. Thus downstream connected nodes (somewhere outside your automata logic) can test for these (via CastAs) and call into the state.
A prominent example would be the ability to notify a state that some mouse keyboard interaction happened, that the state might want to react to.
TODO: clean up this example for 2020.2 where the This node is available. We should be able to get rid of the confusing Reference.
Note: an important part of the design pattern is to have a dedicated interface for this single automata. Don't try to use one interface for different automatas. Only if every automata has its own interface you are free to change that at any time. It is only there to define common ground of all states for this particular automata.
When you stumble over situations like described in #8 you might want to try to find the solution that scales and promises to be versatile. In exchange, you discard some overrated elegance like seen in #9 and trade it for a bit of verbosity.
Welcome to the strategy pattern! _This way of using the strategy pattern is also known as State pattern_
StatePattern.zip
With this pattern, you end up with one dedicated class per automata state. By modeling it that way you can now benefit from all features that classes have e.g.:
TODO: clean up this example for 2020.2 where the This node is available. We should be able to get rid of the confusing Reference.
Note: an important part of the design pattern is to have a dedicated interface for this single automata. Don't try to use one interface for different automatas. Only if every automata has its own interface you are free to change that at any time. It is only there to define common ground of all states for this particular automata.