title: Decorator Pattern Issue
body: <p>I am using a decorator pattern to add style and options to an output stream (console).</p>
  
  <blockquote>
    <p>It's an console app that adds color to the command line output. The
    decorator adds the color. The condition in the <strong>ClientClass</strong> is that
    <strong>if an error</strong> occurred then decorate with <strong>red text</strong> and <strong>if no error</strong> occurred then decorate with <strong>green text</strong>. The color
    decorator therefore has optional calls that only the <strong>ClientClass</strong>
    can know about.</p>
    
    <p>* Copy of the OP's comment on one of the answers</p>
  </blockquote>
  
  <p>The problem I have is this:  I am passing in my decorator to a class via the constructor.  But the decorated object requries that I call two methods that are not in the base class i.e. that being decorated.</p>
  
  <p>Is this bad?  Shouldnt i only be calling those methods which are available in all decorated classes?</p>
  
  <p>As an example:</p>
  
  <pre><code>&lt;?php
  
  abstract class MyAceBaseClass
  { 
      abstract function doYourThing();
  }
  
  
  class MyAceBaseClassDecoratorA extends MyAceBaseClass
  { 
      protected $aceBaseClass;
  
      protected $amount = 0;
  
      public function __construct($aceBaseClass)
      { 
           $this-&gt;_aceBaseClass = $aceBaseClass;
      }
  
      public function doYourThing()
      {
          $result = $aceBaseClass + $this-&gt;amount;
          return $result;
      }
  
      public function decoratorFunctionA()
      {
          $this-&gt;amount = 10;
      }
  
      public function decoratorFunctionB()
      {
          //----
      }
  }
  
  class ClientClass
  { 
      private $aceObject;
  
      public function __construct(MyAceBaseClass $aceObject) 
      {
           $this-&gt;aceObject = $aceObject;       
      }
  
      public function run()
      {
           if ($someCondition) {
               $this-&gt;aceObject-&gt;decoratorFunctionA();
               $this-&gt;aceObject-&gt;decoratorFunctionB();
           }
  
           $result = $this-&gt;aceObject-&gt;doYourThing();
  
           echo $result;
      }
  }
  </code></pre>
  
  <p>So as you can see, the client class needs to call decoratorFunctionA and decoratorFunctionB (which are only availble in the decorator class) before it can call the abstract method doYourThing() available to all classes extending MyAceBaseClass.  This feels wrong.</p>
  
  <p>I think the decorator implementation is correct but now i am stuck with this other problem</p>
  
  <p>How can i resolve this?</p>
  
  <p>The client class might not need both decoratorFunctionA() and decoratorFunctionB() called, it might only need 1 or none so I cant simply call these automatically in the doYourThing call.</p>
  
  <p>A possibility is to have an interface for MyAceBaseClassDecoratorA but then i am kind of defeating the purpose of using the decorator in the first place.</p>