Example #1
0
        public void PrintVegetarianMenu()
        {
            Iterator iterator = allMenus.CreateIterator();

            Console.WriteLine("\nVegetarian menu\n----");
            while (iterator.HasNext())
            {
                MenuComponent menuComponent = (MenuComponent)iterator.Next();
                try
                {
                    if (menuComponent.Vegetarian)
                    {
                        menuComponent.Print();
                    }
                } catch (InvalidOperationException e) { }
            }
        }
        public object Next()
        {
            if (HasNext())
            {
                Iterator      iterator  = (Iterator)stack.Peek();
                MenuComponent component = (MenuComponent)iterator.Next();
                if (component is Menu)
                {
                    stack.Push(component.CreateIterator());
                }

                return(component);
            }
            else
            {
                return(null);
            }
        }