Download presentation
Presentation is loading. Please wait.
1
Strategy AKA Policy Dale Willey Ian Price
2
Overview Definitions Difference between Strategy pattern and strategy Where would you use this? Challenges
3
Definitions (Metsker) Encapsulate alternative strategies, or approaches, in separate classes that each implement a common operation. (GoF) Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently form clients that use it.
4
What That Really means... Multiple functions that take the same arguments and return something of the same type.
5
Strategy Pattern vs strategy strategy is a single way of doing things Strategy Pattern is applying different strategies Discussion?
6
Questions so far...
7
Example: Playing Monopoly How could the strategy pattern be applied here? What different strategies are there?
8
President’s Cabinet In the context of the President’s advisors, how could the strategy pattern be applied here? What different strategies are there?
9
VCR Does a VCR implement a strategy pattern with respect to playing tapes? With setting the clock? A single VCR? All VCRs?
10
Challenges Reexamine the definitions... (Metsker) Encapsulate alternative strategies, or approaches, in separate classes that each implement a common operation. (GoF) Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently form clients that use it. What kind of relationship are they describing? 1-1? 1-∞?
11
Challenges (cont) How is this like Chain of Responsibility?
12
Challenges (cont cont) Are business contingency plans Chains of Responsibility or Strategies?
13
Challenges (cont cont cont) Is a random Chain of Responsibility a Strategy?
14
Challenges (still cont) Is a completely predictable way of applying strategies a Strategy pattern? Is maxing the bet every time in poker (constantly bluffing) an example of a Strategy pattern?
15
Review Strategy Pattern uses 1 to n strategies in a modular way The point to the Strategy Pattern is in having and using strategies rather than emphasis on the selection method
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.