Sunday, October 7, 2007

Strategy pattern - real world (2)

Strategy Definition:
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.

IComparable is a good example of the Strategy pattern. IComparable defines a single member called CompareTo (Object o). This allows different classes to define different strategies for comparison. As long as the class implements IComparable and the CompareTo member, the implementation is up to the class itself.
blog comments powered by Disqus