Define a family of algorithms, encapsulated each one and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Avoid problems such as hard-wiring algorithms into classes that require them.
Use the Strategy pattern when
- many related classes differ only in their behavior.
- You need different variants of an algorithm
- An algorithm uses date that clients shouldn't know about.
- A class defines many behaviors and these appear as multiple-conditional statements, move related conditional brances into theiw own Strategy class.