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!)
Joined: Feb 26, 2005
Some of us dont have the book. Hard to visualize what you mean.
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.