Consequences of Using the Strategy Pattern
In this lesson, we will compare strategy and state patterns and explain the consequences of using the strategy pattern.
We'll cover the following...
Comparison of strategy and state
When discussing the Strategy pattern, its relationship with the pattern preceding it in the Design Patterns book deserves special mention. The design patterns State and Strategy are closely related. As Robert C. Martin puts it,
“All instances of the State pattern are also instances of the Strategy pattern, but not all instances of Strategy are State.”
This observation leads us to a recommendation by John Vlissides, co-author of Design Patterns, which states that you should, “[l]et the intents of the patterns be your guide to their differences and not the class structures that
implement them” .
And indeed, even though State and Strategy have a similar ...