1. What are the Example of Strategy Pattern in the .NET Framework?
- ArrayList, sort method, IComparer
- Class should be Open For Extension, Closed For Modification (Open-Closed Principle )
- 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