Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            /* on C# is not needed an iterator implementation for collection. They already implements
             * this pattern. Program writen is only for learning purposes*/
            PancakeHouseMenu pancakeHouseMenu = new PancakeHouseMenu();
            DinerMenu        dinerMenu        = new DinerMenu();
            Waitress         waitress         = new Waitress(pancakeHouseMenu, dinerMenu);

            waitress.PrintMenu();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            PancakeHouseMenu pancakeHouseMenu = new PancakeHouseMenu();
            DinnerMenu       dinnerMenu       = new DinnerMenu();
            AtJackMenu       atJackMenu       = new AtJackMenu();

            Waitress waitres = new Waitress(pancakeHouseMenu, dinnerMenu, atJackMenu);

            waitres.PrintMenu();
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            PancakeHouseMenu pancakeHouseMenu = new PancakeHouseMenu();
            DinerMenu        dinerMenu        = new DinerMenu();

            Waitress waitress = new Waitress(pancakeHouseMenu, dinerMenu);

            waitress.PrintMenu();
            PrintMenu();
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public static void PrintMenu()
        {
            PancakeHouseMenu pancakeHouseMenu = new PancakeHouseMenu();
            DinerMenu        dinerMenu        = new DinerMenu();

            List <MenuItem> breakfastItems = pancakeHouseMenu.GetMenuItems();

            MenuItem[] lunchItems = dinerMenu.GetMenuItems();

            Console.WriteLine("USING FOR EACH");

            foreach (MenuItem menuItem in breakfastItems)
            {
                Console.WriteLine(menuItem.GetName());
                Console.WriteLine("\n" + menuItem.GetPrice());
                Console.WriteLine("\n" + menuItem.GetDescription());
            }
            foreach (MenuItem menuItem in lunchItems)
            {
                Console.WriteLine(menuItem.GetName());
                Console.WriteLine("\n" + menuItem.GetPrice());
                Console.WriteLine("\n" + menuItem.GetDescription());
            }

            Console.WriteLine("USING FOR LOOPS");
            for (int i = 0; i < breakfastItems.Count; i++)
            {
                MenuItem menuItem = (MenuItem)breakfastItems[i];
                Console.WriteLine(menuItem.GetName());
                Console.WriteLine("\n" + menuItem.GetPrice());
                Console.WriteLine("\n" + menuItem.GetDescription());
            }

            for (int i = 0; i < lunchItems.Length; i++)
            {
                MenuItem menuItem = lunchItems[i];
                Console.WriteLine(menuItem.GetName());
                Console.WriteLine("\n" + menuItem.GetPrice());
                Console.WriteLine("\n" + menuItem.GetDescription());
            }
        }
Ejemplo n.º 5
0
        /*
         * The Iterator Pattern
         *
         * Provides a way to access the elements of an aggregate object
         * sequentially without exposing its underlying representation.
         *
         * Example:
         * Print out menu of the cafe and print out the categories of the meal.
         *
         * 1. Ask the object for its iterator.
         * 2. Use iterator to iterate through the items in the aggregate.
         * 3. Iteration code works with any kind of agregate objects.
         *
         * A class should have only one reason to change. (Design Principle #6)
         *
         *
         */

        static void Main(string[] args)
        {
            var         pancakeHouseMenue = new PancakeHouseMenu();
            var         dinerMenu         = new DinerMenu();
            IEnumerable vegMenu           = new VegeterianMenu();

            IIterator pancakeHouseIter = pancakeHouseMenue.CreateIterator();
            IIterator dinerMenuIter    = dinerMenu.CreateIterator();

            //IEnumerator vegMenuEnu = vegMenu.GetEnumerator();

            Console.WriteLine("MENU (with iterators)\n----\nBREAKFAST");
            PrintMenu(pancakeHouseIter);
            Console.WriteLine("LUNCH");
            PrintMenu(dinerMenuIter);
            Console.WriteLine("VEGETERIAN");
            foreach (var i in vegMenu)
            {
                Console.WriteLine(i as string);
            }
        }