• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about page 374 of Head First Design Patterns

 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand the code that I am talking about is a pretty tough piece. But someone who has reviewed the book like Mark Spritzler should be able to help me , I hope. Still waiting :roll:
 
reply
    Bookmark Topic Watch Topic
  • New Topic