Example #1
0
        /// <summary>
        /// O padrão State permite que um objeto altere o seu comportamento quando o seu estado interno muda. O objeto parecerá ter mudado de classe.
        /// </summary>
        private static void TestComposite()
        {
            Menu dinerMenu = new Menu("Diner", "Lunch");

            dinerMenu.AddItem(new Composite.MenuItem("Vegetarian BLT", "(Fakin) Bacon with lettuce & tomato on whole wheat", true, 2.99));
            dinerMenu.AddItem(new Composite.MenuItem("BLT", "Bacon with lettuce & tomato on whole wheat", false, 2.99));
            dinerMenu.AddItem(new Composite.MenuItem("Soup of the day", "Soup of the day, with a side of potato salad", false, 3.29));
            dinerMenu.AddItem(new Composite.MenuItem("Hotdog", "A hot dog, with saurkraut, relish, onions, topped with cheese", false, 3.05));

            Menu pancakeMenu = new Menu("Pancake", "Breakfast");

            pancakeMenu.AddItem(new Composite.MenuItem("K&B's Pancake Breakfast", "Pancakes with scrambled eggs, and toast", true, 2.99));
            pancakeMenu.AddItem(new Composite.MenuItem("Regular Pancake Breakfast", "Pancakes with fried eggs, sausage", false, 2.99));
            pancakeMenu.AddItem(new Composite.MenuItem("Blueberry Pancakes", "Pancakes made with fresh blueberries", true, 3.49));
            pancakeMenu.AddItem(new Composite.MenuItem("Waffles", "Waffles of your choice with blueberries or strawberries", true, 3.59));

            Menu dessertMenu = new Menu("Dessert", "Dessert, of course");

            dessertMenu.AddItem(new Composite.MenuItem("Veggie Burger and Air Fries", "Veggie burger on a whole wheat bun", true, 3.99));
            dessertMenu.AddItem(new Composite.MenuItem("Cheesecake", "Creamy New York Cheesecake, with chocolate graham crust", false, 1.89));
            dinerMenu.AddItem(dessertMenu);

            var items = new IMenuComponent[2];

            items[0] = dinerMenu;
            items[1] = pancakeMenu;

            var iterator = new MenuIterator(items);

            iterator.PrintMenu();
        }
Example #2
0
        public void RunIterator()
        {
            var menuIterator = new MenuIterator(arrayMenuItem);

            while (menuIterator.HasNext())
            {
                var menuItem = (MenuItem)menuIterator.Next();
            }
        }
        public void PrintMenu()
        {
            MenuIterator menuIterator = new MenuIterator(_menus);

            while (menuIterator.HasNext())
            {
                IMenu menu = menuIterator.Next() as IMenu;
                PrintMenu(menu.CreateIterator());
            }
        }