posted 9 years ago
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.).