Tuesday, October 9, 2007

Strategy Pattern (4) Summary

Six days have passed since I first wrote notes about Strategy Pattern. But I kept thinking about it, there are a few questions that make me think:

1. What are the Example of Strategy Pattern in the .NET Framework?

  • ArrayList, sort method, IComparer
2. When do I apply the Strategy Pattern in my everyday Web Applications?

  • Class should be Open For Extension, Closed For Modification (Open-Closed Principle )
3. When not to use it?
  • David Hayden's blog: It is best not to use them just for the sake of using them, because you will run the risk of needless complexity (application design smells) in your applications.
  • Agile Principles, Patterns, and Practices in C#: Design patterns are wonderful things. They can help you with many design problems. But the fact that they exist does not mean that they should always be used. In some cases, the cost of the pattern was higher than the benefit it yielded.

4. What benefits does it bring?

  • David Hayden's blog
  • Open-Closed Principle
  • Implementing a new comparison method for sorting objects in an ArrayList does not require a change to the ArrayList Class. This class is essentially closed for modification. However, because we can pass in an object that implements IComparer, the class is open for extension. Extending this class only requires new code ( classes ) to be written that implement IComparer, not changes to existing code.
  • Loosely couple your main classes in an application from lower-level detail classes / algorithms
blog comments powered by Disqus