vvvv / VL-Language

The official repo for the design of the VL programming language
31 stars 0 forks source link

[Design pattern Proposal] How to patch the Strategy pattern #10

Open gregsn opened 4 years ago

gregsn commented 4 years ago

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_

image

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.