Tagged “State”
2 articles with this tag.
- StateLet an object change its behaviour when its internal state changes, by delegating to state objects instead of switch statements. A runnable Java 21 order lifecycle (awaiting payment, paid, shipped, delivered, cancelled), enum and sealed alternatives, State versus Strategy, and state machines in practice.
- Strategy vs State vs Template MethodThree patterns that all vary behaviour: Strategy swaps a whole algorithm by composition, State swaps behaviour as an object's lifecycle changes, and Template Method varies steps by inheritance. Side-by-side code, the deciding questions and how to choose.