• Post Reply Bookmark Topic Watch Topic
  • New Topic

output doubt  RSS feed

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • 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



 
Vijitha Kumara
Bartender
Posts: 4001
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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.).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!