370
99.9
Mar 06, 2011
Hi,
for example when you implement IComparable interface, you define the strategy for comparing which may differ per implementation, but the contract remains the same. You may replace the implementation without affecting the client. The same could be with ICloneable etc.
Hope this helps,
Robert
1,284
100.0
Mar 06, 2011
I have a brief blog post here..
http://30minutestotechnirvana.blogspot.com/2007/12/session-1.html
In a nutshell.. (extracted)
Applications of Strategy pattern in .NET Framework
(1) Array and ArrayList provides capability to sort object. By default they use QuickSort algorithm. The Sort method will use the IComparable implementation for each element to handle the comparisons necessary for sorrting. To change the sortig strategy use the overload of Sort that takes an IComparer as a parameter.
ICompararer.Compare is then used for the comparisons.
The new List makes heavy use of the strategy pattern. In addition to the updated Sort method, the find-related methods, BinarySearch and others all take parameters that allow parts of the respective algorithms to vary based on the needs of the caller. The use of Predicatedelegate in the FindAll method lets the caller use any method as a filter for the List so long as it takes the appropriate object type and returns a boolean.
Hope this helps.