title: How do I reduce delegation boilerplate?
body: <p>I have a class that implements an interface.  There's another class that implements this interface, too, and an instance of this second class backs my class's implementation.</p>
  
  <p>For many of the methods specified by the interface, my class simply forwards them straight to the second class.</p>
  
  <pre><code>public class MyClass implements MyInterface
  {
      private OtherClass otherClassInstance; // Also implements MyInterface.
      // ...
      void foo() { otherClassInstance.foo(); }
      void bar() { otherClassInstance.bar(); }
      void baz() { otherClassInstance.baz(); }
      // ...
  }
  </code></pre>
  
  <p>Simply deriving my class from the second class would eliminate all of this, but it doesn't make sense because the two classes are unrelated to each other (besides implementing a common interface).  They represent different things - it just so happens that a lot of my class's implementation copies that of the other class.  In other words, my class is implemented atop the second class, but it is not itself a subset of the second class.  As we know, inheritance is meant to express an "is-a" relationship, not to share implementation, so it's inappropriate in this case.</p>
  
  <p><a href="http://www.youtube.com/watch?feature=player_detailpage&amp;v=aAb7hSCtvGw#t=2524s" rel="nofollow">This</a> portion of a talk by Joshua Bloch illustrates the situation well.</p>
  
  <p>I know that Java doesn't have any language support for delegation.  However, is there at least some way to clean up my class's implementation so it isn't so redundant?</p>