public object Next() { if (HasNext()) { IIterator iterator = (IIterator)_stack.Peek(); MenuComponent component = (MenuComponent)iterator.Next(); if (component is Menu && !(iterator is CompositeIterator)) { _stack.Push(component.CreateIterator()); } return(component); } else { return(null); } }
public void PrintVegetarianMenu() { IIterator iterator = _allMenus.CreateIterator(); Console.WriteLine("\nVEGETARIAN MENU\n----"); while (iterator.HasNext()) { MenuComponent menuComponent = (MenuComponent)iterator.Next(); try { if (menuComponent.IsVegetarian()) { menuComponent.Print(); } } catch (NotSupportedException) { } } }