Simberon Design Minute
 

Strategy Pattern

The Strategy design pattern allows you to extract an algorithm into its own class. Whenever you need to use that algorithm, you can create an instance of that class and call it. You can pass strategy objects as parameters and store them in instance variables. This allows the client code to be more generic and to use whichever strategy it's given rather than hard-coding the strategy each time.

It's interesting to note that the Strategy pattern is often interoperable with the Interpreter pattern. Where the Strategy pattern writes code in the native programming language to code the algorithm, the Interpreter pattern interprets an evaluation tree. Functionally, though, they both accomplish the same purpose - to separate an algorithm from the users of that algorithm.

Download