37
Use and Misuse
of Patterns Caution!
A pattern
is a solution to a problem in a context. If the context is missing, don’t
apply the pattern
The
context for the Strategy pattern is that you need to swap strategies
dynamically or that you need to be
able to easily add new strategies that are not yet known. If this context is
missing, simply subclass the
Context class and hardcode the known strategies to avoid the runtime overhead
of the strategy pattern