Mid From PDF GoF Patterns Gang of Four Patterns

Context (Sorter):?

  • The Sorter class acts as the context that uses the strategy. It has a method

SetStrategy that allows clients to set the desired sorting strategy dynamically. The

Sort method delegates the sorting task to the currently set strategy.

public class Sorter
{
private ISortStrategy _strategy;
public void SetStrategy(ISortStrategy strategy) => _strategy =

strategy;

public void Sort(List<int> list) => _strategy.Sort(list);
}

More from Design Patterns in C#

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details