Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes OO, Patterns, UML and Refactoring and the fly likes Decorator Pattern in Head First Design Patterns doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Decorator Pattern in Head First Design Patterns doubt" Watch "Decorator Pattern in Head First Design Patterns doubt" New topic
Author

Decorator Pattern in Head First Design Patterns doubt

Norbert Waage
Greenhorn

Joined: Jun 08, 2012
Posts: 3

Hello everybody, this is my first post here.

I was reading the chapter 3 from Head First Design Patterns, about the Decorator Pattern.

In the class diagram, they created an abstract class to be the base of each decorator. But they didn't put the reference to the object being wrapped inside this abstract class. This reference was created on each new decorator, instead.

I am confused about this.

In the Wikipedia class diagram, this is different, with the reference to the wrapped object inside the decorator abstract class, which appears to be the best solution for me.

Is there any reason for the Head First author to put it that way?

Thank you guys!

(I'm sorry if I made any mistake in my English!)
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Some of us dont have the book. Hard to visualize what you mean.
Norbert Waage
Greenhorn

Joined: Jun 08, 2012
Posts: 3

I'm sorry.

Here is the diagram from the book.

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
If that 'component' arrow in the Head First book (either as UML standard or the book's standard) means 'composition', then maybe you can write the author about it. It could have been left out because the arrow already implies that relationship.

Also, the head first version, sort of adds a layer to identify that those components are CondimentDecorators, without adding anything, except the required getDescription().

I would say, that in the end, both the wiki and head first are okay; it is up to your choice where to put the decorated object.

Welcome to Javaranch!
 
wood burning stoves
 
subject: Decorator Pattern in Head First Design Patterns doubt