I have a question regarding page 374 of Head First Design
Patterns. This is regarding the Composite Iterator in the Composite pattern chapter used in printing the vegetarian menu.
If you see the output in that page, the dessert menu items are getting printed 2 times. This bug happens only when you use an external iterator where the waitress controls the iteration using the Composite Iterator. If you implement the printing of the vegetarian menu using an internal iterator (such that Menu manages the iteration by itself calling the method to print the vegetarian menu recursively), that does not make use of the composite iterator, then the dessert menu items get printed only once. This looks like a bug in the composite iterator code. But I do not see any bug in the Composite Iterator's logic as far as I can bend my mind to understand it. Does someone know of a bug in that or is this some bug in the
Java API - Stack, Iterator etc?