Example #1
0
        static void Main(string[] args)
        {
            SortedList list = new SortedList();

            list.Add("Martin");
            list.Add("Martin2");
            list.Add("Martin3");
            list.Add("Martin4");

            QuickSort sort = new QuickSort();
            list.SetSortStrategy(sort);

            list.Sort();

            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            //Have Base Reference and Create Object of Class
            BaseAlgorithm bubbleSort = new BubbleSort();

            bubbleSort.AlgorithmImplementation();

            BaseAlgorithm quickSort = new QuickSort();

            quickSort.AlgorithmImplementation();

            //The other way of having this is by creating a Dictionary and in it's values initilize object of each class
            //Have one property as abstract overridden in each sub handlers defined with unique name.
            //In this way we can have a Class Initialzation in dictionary itself and we dont have to create seperate Class as ContextHandlers
            //Please refer my Runtime Polymorphism example for more details.

            Console.ReadKey();
        }
Example #3
0
        public static ISortingStrategy GetSortingStrategy(ObjectToSort objectToSort)
        {
            ISortingStrategy sortingStrategy = null;

            switch (objectToSort)
            {
                case ObjectToSort.StudentNumber:
                    sortingStrategy = new MergeSort();
                    break;
                case ObjectToSort.RailwayPassangers:
                    sortingStrategy = new HeapSort();
                    break;
                case ObjectToSort.CountryResidents:
                    sortingStrategy = new QuickSort();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Unsupported object to sort");
            }

            return sortingStrategy;
        }