示例#1
0
        public void PrintMenu()
        {
            IITerator pancakeHouseMenuIterator = pancakeHouseMenu.CreateIterator();

            Console.WriteLine("BREAKFAST");
            PrintMenu(pancakeHouseMenuIterator);
            IITerator dinerMenuIterator = dinerMenu.CreateIterator();

            Console.WriteLine("LUNCH");
            PrintMenu(dinerMenuIterator);
        }
示例#2
0
        static void Main(string[] args)
        {
            PancakeHouseMenu pancakeMenu = new PancakeHouseMenu();
            DinnerMenu       dinnerMenu  = new DinnerMenu();

            #region Bad implementation of PrintMenu() method

            //List<MenuItem> breakfastItems = pancakeMenu.MenuItems; // waitress is dependent on type List<MenuItem>
            //MenuItem[] dinnerItems = dinnerMenu.MenuItems; // waitress is also dependent on type MenuItem[]

            //foreach (var menuItem in breakfastItems)
            //{
            //    Console.WriteLine(menuItem.Name);
            //    Console.WriteLine(menuItem.Price);
            //    Console.WriteLine(menuItem.Description);
            //}

            //foreach (var menuItem in dinnerItems)
            //{
            //    Console.WriteLine(menuItem.Name);
            //    Console.WriteLine(menuItem.Price);
            //    Console.WriteLine(menuItem.Description);
            //}

            #endregion

            IIterator <MenuItem> pancakeIterator = pancakeMenu.CreateIterator();
            IIterator <MenuItem> dinnerIterator  = dinnerMenu.CreateIterator();

            Console.WriteLine("---Menu---");
            Console.WriteLine();
            Console.WriteLine("--Breakfast--");
            PrintMenu(pancakeIterator);
            Console.WriteLine();
            Console.WriteLine("--Lunch--");
            PrintMenu(dinnerIterator);
        }