• 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

Head First Design Patterns Page 92

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic