Comparing Strategy and State
The refactored code consists almost entirely of simple methods in simple classes. This is an advantage in its own right and makes adding new strategies easy. The refactoring relies primarily on the idea of distributing an operation across a related group of classes. In this regard, STRATEGY is identical to STATE. In fact, many developers wonder whether these are really different patterns.
On the one hand, in the real world, strategies (such as recommending a firework) and states (such as a carousel door with a one-touch control button) are clearly different ideas. This real difference leads to different problems in modeling states and strategies. For example, transitions are important when modeling states but usually ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access