public class Librarian { // librarian sort strategy storage protected ISortStrategy sortStrategy; public void SetSortType(ISortStrategy sortStrategy) { this.sortStrategy = sortStrategy; } public void SortBooks(List books) { if (sortStrategy != null) sortStrategy.Sort(List books); } } // sort interface public interface ISortStrategy { void Sort(List books); } public class SortAlpha : ISortStrategy { public void Sort(List books) { // alphabetical sort } } public class SortDate : ISortStrategy { public void Sort(List books) { // publish date sort } } // example use public class Program { public static void Main(string[] args) { var books = new List(); var lib = new Librarian(); lib.SetSortType(new SortAlpha()); lib.SortBooks(books); // sorts the books alphabetically lib.SetSortType(new SortDate()); lib.SortBooks(books); // sorts the books by publication date } }