Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decorator Pattern in Head First Design Patterns doubt

 
Norbert Waage
Greenhorn
Posts: 3
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of us dont have the book. Hard to visualize what you mean.
 
Norbert Waage
Greenhorn
Posts: 3
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry.

Here is the diagram from the book.

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic