File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Head First Design Patterns  Page 92 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Head First Design Patterns  Page 92" Watch "Head First Design Patterns  Page 92" New topic
Author

Head First Design Patterns Page 92

Gopal Bairwa
Greenhorn

Joined: Oct 05, 2004
Posts: 2
Head First Desin Patterns Chapter 3 Page 92 : Can anybody tell what is signifcance of having "CondimentDecorator" abtract decorator class which extends the abstract "Beverage" class. Why can't the concrete decorators extend the abstract "Beverage" class.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hello Gopal, welcome to Javaranch.

I'm going to slide your post over to the OO, Patterns, UML and Refactoring forum. Your question might kick up more discussion there...
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1007
    
    3
Without ever having seen the book in question, I'll take a stab at the answer anyhow. I assume it follows the standard set in the Gang of Four "Design Patterns" book.

The abstract CondimentDecorator class adds methods and fields that are common to all Decorators but not needed by plain Beverage subclasses. For instance, CondimentDecorator probably declares a constructor that takes the Beverage to decorate and stores it in an instance field.

Also, it cuts way down on the amount of typing needed for the subclasses if CondimentDecorator implemented all the methods of the Beverage class to just delegate the calls to the same methods in the decorated Beverage object. Then the various decorator classes can just override the methods for which they have specific needs. This becomes more important as the number of methods in the base Beverage class class increases.

Ryan
[ May 09, 2005: Message edited by: Ryan McGuire ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This chapter is online HERE and it makes a great impression for the book.

One difference I see between the decorator and the ConcreteComponent (on p 91) is that each decorator has a reference to the object being decorated. Is that enough reason to have the abstract decorator? Can you think of any other helper methods it might have to simplify calling down the chain of decorators or collecting their results?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Design Patterns Page 92