• 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

output doubt

 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may i know the below program is giving the output from all classes even though i am calling it only once,[this is a pattren].

may i know the execution process. in other words how is this giving the output

you are getting a computer and a disk and a CD and a Moniter




 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here ComponentDecorator abstract class defines the description method which other sub classes will have to override. You are creating different decorators (Disk,CD,Monitor) and at run-time they delegate(forward) method calls to the objects they decorate. Like here, when you call the description() method in Computer reference(which is actually of type Monitor) it delegates the method call to it's Computer reference (of type CD) and so on. So at last it reaches object type Computer which prints out the "computer" and rest is printed after that (disk,CD etc.).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic