Strategy Pattern
Summary
- The Strategy pattern involves removing an algorithm from its host class and putting it in a separate class.
- The context will often contain a switch statement or a cascading if statement, where information is processed to reach a decision on which Strategy to adopt.
Class diagram: (see Strategy Pattern code review)
Usage
Use the Strategy pattern when:
- Many related classes differ only in their behaviour.
- There are different algorithms for a given purpose, and the selection criteria can be codified.
- The algorithm uses data to which the client should not have access.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!