static void Main(string[] args) { var context = new Context(new StrategyA()); context.ContextInterface(); context = new Context(new StrategyB()); context.ContextInterface(); context = new Context(new StrategyC()); context.ContextInterface(); }
static void Main(string[] args) { var context = new Context(() => Console.WriteLine("Called Strategy A")); context.ContextInterface(); context = new Context(() => Console.WriteLine("Called Strategy B")); context.ContextInterface(); context = new Context(() => Console.WriteLine("Called Strategy C")); context.ContextInterface(); }
static void Main(string[] args) { Context context = new Context(); int resultA = context.ExecuteStrategy(3, 4); int resultB = context.ExecuteStrategy(4, 4); int resultC = context.ExecuteStrategy(6, 4); Console.WriteLine(resultA); Console.WriteLine(resultB); Console.WriteLine(resultC); }
static void Main(string[] args) { Context context; context = new Context(new StrategyA()); context.Execute(); context = new Context(new StrategyB()); context.Execute(); context = new Context(new StrategyC()); context.Execute(); }
static void StrategyPattern() { Console.WriteLine("\n\nStrategy Pattern"); var context = new StrategyPattern.Context(new Type1StrategyA(), new Type1StrategyB()); context.Apply(); context.SetStrategyA(new Type2StrategyA()); context.Apply(); context.Execute(); context.SetStrategyB(new Type2StrategyB()); context.Execute(); }
static void Main(string[] args) { #region MyRegion // Three contexts following different strategies Context c = new Context(new ConcreteStrategyA()); c.ContextInterface(); Context d = new Context(new ConcreteStrategyB()); d.ContextInterface(); Context e = new Context(new ConcreteStrategyC()); e.ContextInterface(); #endregion #region MyRegion SortedList studentRecords = new SortedList(); studentRecords.Add("Samual"); studentRecords.Add("Jimmy"); studentRecords.Add("Sandra"); studentRecords.Add("Anna"); studentRecords.Add("Vivek"); studentRecords.SetSortStrategy(new QuickSort()); studentRecords.Sort(); studentRecords.Display(); #endregion Console.ReadLine(); }