title: Implementing Class Adapter Pattern in Java
body: <p>While reading up on the Class Adapter pattern in <a href="http://shop.oreilly.com/product/9780596007126.do" rel="noreferrer">Head First Design Patterns</a>, I came across this sentence:</p>
  
  <blockquote>
    <p>class adapter... because you need multiple inheritance to implement it, which is not possible in Java</p>
  </blockquote>
  
  <p>Just to experiment, I tried the following:</p>
  
  <pre><code>interface MyNeededInterface{
      public void operationOne(MyNeededInterface other);
      public MyNeededInterface operationTwo();
  }
  
  public class ThirdPartyLibraryClass{
      public void thirdPartyOp();
  }
  </code></pre>
  
  <p>Suppose I create :</p>
  
  <pre><code>class ThirdPartyWrapper extends ThirdPartyLibraryClass implements MyNeededInterface{
  
      @Override
      public void operationOne(ThirdPartyWrapper other){
          this.thirdPartyOp();
          dosomeExtra();
      }
      @Override
      public ThirdPartyWrapper operationTwo(){
          int somevalue = doSomeThingElse();
          return new ThirdPartyWrapper(somevalue);
      }
  }
  </code></pre>
  
  <p>In my code, I can use:</p>
  
  <pre><code>MyNeededInterface myclass = createThirdPartyWrapper();
  myclass.operationOne(someobj);
  ...
  </code></pre>
  
  <p>Is this not the Class Adapter pattern?</p>