title: Using additional methods in the Decorator pattern
body: <p>In the GoF Design Patterns book's chapter about the Decorator pattern there's an example with GUI controls. Here's an example code in C++ (I've changed it a little):</p>
  
  <pre><code>class VisualComponent
  {
      public:
      virtual void Draw() = 0;
  };
  
  class TextView : public VisualComponent
  {
      // ...
  };
  
  class Decorator : public VisualComponent
  {
      private:
      VisualComponent * component;
  
      public:
      Decorator(VisualComponent * c)
          : component(c)
      {}
      virtual void Draw()
      {
          component-&gt;Draw();
      }
  };
  
  class ScrollDecorator : public Decorator
  {
      public:
      ScrollDecorator(VisualComponent * c)
          : Decorator(c)
      {}
      virtual void Draw()
      {
          Decorator::Draw();
      }
      void ScrollTo()   // [1]
      {
          // perform scrolling
      }
  };
  
  class BorderDecorator : public Decorator
  {
      private:
      void DrawBorder()   // [2]
      {
          // draw border
      }
  
      public:
      BorderDecorator(VisualComponent * c)
          : Decorator(c)
      {}
      virtual void Draw()
      {
          Decorator::Draw();
          DrawBorder();
      }
  };
  </code></pre>
  
  <p>The point of the decorator classes is to add new behaviour/appearance/etc... to an object. For example:</p>
  
  <pre><code>VisualComponent myControl = new BorderDecorator(new ScrollDecorator(new TextView)));
  </code></pre>
  
  <p>creates a text view control that is scrollable and has a border. Adding a border is invisible to the client - it's a private method (<code>[2]</code>) and it's called in the <code>Draw()</code> method from the <code>VisualComponent</code> interface.</p>
  
  <p>However, in the example the authors also presented (in the diagram) a method for scrolling the GUI control (<code>[1]</code>). Now, there's nothing more mentioned in the book so I don't know what exactly that method is supposed to do or how it is supposed to behave. Most importantly, I don't know whether it's public (and part of the class's interface) or private.</p>
  
  <p>Assuming it's the latter case, how would it work? The only methods defined by the <code>VisualComponent</code> interface are <code>Draw()</code> and <code>Resize()</code>, none of which really applies to the task of scrolling the control (usually by clicking and dragging a mouse by the user). I've marked possible invocations with <code>[3]</code> but I'm not sure they're right.</p>
  
  <p>Assuming it's the former case, the method extends the class's interface with a new public method and that's the gist of my question. How is the client supposed to call that method? If it's not the top-level decorator (like in our example) it can't access the <code>component</code> field as it's private.</p>
  
  <p>So, to summarize - can the decorator classes add new <strong>public</strong> methods? If so, how are these supposed to be called? If not (in which case they can only add new <strong>private</strong> methods), should these methods <strong>extend the behaviour of the object ONLY in a way which fits the behaviour defined in the component interface</strong> (<code>VisualComponent</code> in our case)? For example, if the component interface only defined a <code>Draw()</code> method, should these new private methods only deal with drawing/appearance?</p>