Esempio n. 1
0
        static void Main(string[] args)
        {
            Context ct = new Context();

            ct.SetStrategy(new StrategyA());
            ct.ContextInterface();
            ct.SetStrategy(new StrategyB());
            ct.ContextInterface();
            ct.SetStrategy(new StrategyC());
            ct.ContextInterface();
            Console.ReadKey();
        }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Context context;

            context = new Context(new StrategyA());
            context.ContextInterface();

            context = new Context(new StrategyB());
            context.ContextInterface();

            Console.ReadLine();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Context context;

            context = new Context(new ImplementationOne());
            context.ContextInterface();

            context = new Context(new ImplementationTwo());
            context.ContextInterface();

            Console.ReadKey();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Context s = new Context(new ConcreteStrategyA());

            s.ContextInterface();

            s = new Context(new ConcreteStrategyB());
            s.ContextInterface();

            s = new Context(new ConcreteStrategyC());
            s.ContextInterface();

            Console.Read();
        }
        static void Main(string[] args)
        {
            Context context;

            // Three contexts following different strategies
            context = new Context(new ConcreteStrategyA());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyB());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyC());
            context.ContextInterface();

            Console.ReadKey();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            //Basic

            Context context;

            context = new Context(new ConcreteStrategyA());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyB());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyC());
            context.ContextInterface();

            Console.ReadLine();


            //Real world scenario

            //Add records to the list
            SortedListContext sortListContext = new SortedListContext();

            sortListContext.Add("Sam");
            sortListContext.Add("Tom");
            sortListContext.Add("Jim");
            sortListContext.Add("John");
            sortListContext.Add("Amy");


            sortListContext.SetSortedListContext(new MergeSort());
            sortListContext.sort();

            //different sort Type

            sortListContext.SetSortedListContext(new QuickSort());
            sortListContext.sort();


            //different

            sortListContext.SetSortedListContext(new ShellSort());
            sortListContext.sort();

            Console.ReadLine();
        }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Context context = new Context(new ConcreteStrategyA());

            context.ContextInterface();
        }