static void Main(string[] args) { // The client code picks a concrete strategy and passes it to the // context. The client should be aware of the differences between // strategies in order to make the right choice. var context = new Context(); Console.WriteLine("Client: Strategy is set to normal sorting."); context.SetStrategy(new ConcreteStrategyA()); context.DoSomeBusinessLogic(); Console.WriteLine(); Console.WriteLine("Client: Strategy is set to reverse sorting."); context.SetStrategy(new ConcreteStrategyB()); context.DoSomeBusinessLogic(); }
// <summary> // Точка входа в программу. // </summary> public static void Main() { // Создаём контекст и инициализируем его первой стратегией. Context context = new Context(new ConcreteStrategy1()); // Выполняем операцию контекста, которая использует первую стратегию. context.ExecuteOperation(); // Заменяем в контексте первую стратегию второй. context.SetStrategy(new ConcreteStrategy2()); // Выполняем операцию контекста, которая теперь использует вторую стратегию. context.ExecuteOperation(); }