title: Design pattern to decouple from third party lib
body: <p>I am trying  decouple a third party library's abstract class. I want to expose a new abstract class which will be exposed to the users rather than the library provided class.<br>
  I initially tried using an adapter but that stills add the import for the third party lib in the adapter class.</p>
  
  <p>I added code below explaining my <strong>new</strong> approach.</p>
  
  <pre><code>   // third party lib
      abstract class ThirdParty&lt;S&gt; { 
         public abstract S doAction(S s);
      }
      // my goal here is to expose a different abstract class which is    decoupled from third party lib
      // exposed to other modules, rather than exposing the third party lib
      abstract class ExposedAbstractClass&lt;S&gt; {
          public abstract S doAction(S source);
          // get hold of type using guava lib
          private final TypeToken&lt;S&gt; typeToken = new TypeToken&lt;S&gt;(getClass()) { };
          public Class&lt;S&gt; getSourceClass() { return (Class&lt;S&gt;) typeToken.getClass()
      }
  
    // internal class
     class Builder&lt;S&gt; extends ThirdPartyLib&lt;S&gt; {
         ExposedAbstractClass exposed;
         public Builder(ExposedAbstractClass exposed) {
           this.exposed = exposed;
         }
         @Override
         public S doAction(S s) {
           return (S) exposed.doAction(s);
         }
     }
     //my approach breaks here when i try to invoke builder 
     class InvokeThirdParty {
         public void invoke (ExposedAbstractClass exposed) {
           Class type = exposed.getSourceClass();
           Builder&lt;type&gt; builder = new Builder(exposed); //doesn't work since Class is runtime type, and T is compile time type 
         }
     }
  </code></pre>
  
  <p>Any guidance in terms of which design pattern to follow here would be very helpful. </p>