3 ms·
It depends, I prefer switches with a single line, which call out to some service to be preferable to the State pattern. This is because the State pattern encour
by radicalbyte 11y ago
It depends, I prefer switches with a single line, which call out to some service to be preferable to the State pattern. This is because the State pattern encourages you to design these "everything and the kitchen sink" style classes.
It's a bit crazy to implement the State pattern than have the various state object just do single calls (or no-ops) when the switching has been implemented to be readable.
Note: if your language doesn't support enumerations and switching over them then the OO pattern may be better. If I didn't had static analysis telling me when I've missed a state then it's a bug waiting to happen. The State pattern makes a missing state hard to miss ;)