- Coin Counter Example continued.
-
Strategy
Design Pattern
- Behavior as an object -- execution of a strategy.
- The abstraction of a strategy. Does the context care
about what really happens?
- The abstract strategy hierarchy. Abstract vs. concrete
strategies.
- The separation of the variant and invariant behaviors of a
system: Encapsulate the invariant into an object and
abstract the variant into an abstract hierarchy
tree. The invariant deals with the variant only
at the abstract level.
- Strategies give us the ability to modify the behavior
dynamically, that is, during the execution of the program.
- The strategy pattern eliminated the subclasses of Ball and
replaced it with smaller, simpler subclasses of AStrategy that
encapsulate only the differences between the behaviors of different
types of Balls.
- The use of "indirection" allows us to change what's going on
"behind the scenes". For instance, all the behaviors of
all the Balls can be changed at once.
- Display strategies example
|