Consequences
The strategy pattern has the
following consequences and drawbacks
-
Families of related algorithms
-
Algorithms are arrange into an inheritance
hierarchy.
-
Similarities between algorithms can be
moved into the Strategy base class.
-
An alternative to subclassing
-
Achieves a clearer, more extensible design
than subclassing context.
-
The algorithm can be varied independent
of the context
-
The algorithm can be changed dynamically
at run time.
-
Strategies eliminate conditional statements
-
When the strategies are lumped into one
class it is hard to avoid conditionals
-
Conditional statements are hard to maintain,
bulky and create uneccessary dependencies
-
A choice of implementations
-
Clients can chose amongst different implementations
with different time and space
trade-offs
-
Clients must be aware of different strategies
-
One drawback is that clients must be aware
of the effects of different strategies
-
Exposes clients to implementation issues
-
Communication overhead between Strategy
and Context
-
Be wary of passing a lot of data between
Context and Strategy in which
most of the concrete Stragy
classes do not use this data.
-
Use tighter coupling to avoid this situation
-
Increased number of objects
-
This pattern increases the number of objects
in an application.
-
This overhead can be reduced by implementing
strategies as stateless
objects and maintaing state in the
context.
BACK NEXT