Strategy Pattern Code Review

Define the Context Object

Code Review

Code Walkthrough

The Context class (object) stores the application data and applies the sort strategy selected against the application data.

class Context { private List<String> list = new List<String>(); private IStrategy sortStrategy;
public Context(IStrategy sortStrategy) { this.sortStrategy = sortStrategy; }
public void AddItem(String name) { list.Add(name); } public void SetSortStrategy(IStrategy sortStrategy) { this.sortStrategy = sortStrategy; } public void Sort() { this.sortStrategy.Sort(list);
foreach (String name in list) { Console.WriteLine(name); } } }