title: 'Head First Design Patterns: Decorator example IS-A and HAS-A confusion
body: <p>I'm trying to get my head around design patterns. I think they may be one step too advanced in my programming abilities as I am struggling quite a bit with them, however my university assignment is to apply them. So here I am.</p>
  <p>I am going through the example of the Decorator Pattern from the Head First book. This is the example:</p>
  <p><a href="https://i.stack.imgur.com/HpLuh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HpLuh.png" alt="Head First Design Patterns: Decorator UML" /></a></p>
  <p>As you can see in the diagram, the <strong>CondimentDecorator</strong> has the IS-A and HAS-A relationship with <strong>Beverage</strong>. However, here is the code they write for the <strong>CondimentDecorator</strong> and one of the condiments, <strong>Mocha</strong>:</p>
  <p><a href="https://i.stack.imgur.com/N65rU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N65rU.png" alt="CondimentsDecorator" /></a></p>
  <p><a href="https://i.stack.imgur.com/fAKCs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fAKCs.png" alt="Mocha" /></a></p>
  <p>In the <strong>CondimentDecorator</strong> class the only thing that it contains is a method <em>getDescription</em>.</p>
  <p>It's the <strong>Mocha</strong> class that contains instantiates the <strong>Beverage</strong> class AND calls <em>getDescription</em>.</p>
  <p>So doesn't this mean that it's the <strong>Mocha</strong> class that has a IS-A and a HAS-A relationship?</p>