title: How to 'wrap' two classes with identical methods?
body: <p>I have to handle two classes with identical methods but they don't implement the same interface, nor do they extend the same superclass. I'm not able / not allowed to change this classes and I don't construct instances of this classes I only get objects of this. 
  What is the best way to avoid lots of code duplication?</p>
  
  <p>One of the class:</p>
  
  <pre><code>package faa;
  
  public class SomethingA {
  
      private String valueOne = null;
      private String valueTwo = null;
  
      public String getValueOne() { return valueOne; }
      public void setValueOne(String valueOne) { this.valueOne = valueOne; }
  
      public String getValueTwo() { return valueTwo; }
      public void setValueTwo(String valueTwo) { this.valueTwo = valueTwo; }
  }
  </code></pre>
  
  <p>And the other...</p>
  
  <pre><code>package foo;
  
  public class SomethingB {
  
      private String valueOne;
      private String valueTwo;
  
      public String getValueOne() { return valueOne; }
      public void setValueOne(String valueOne) { this.valueOne = valueOne; }
  
      public String getValueTwo() { return valueTwo; }
      public void setValueTwo(String valueTwo) { this.valueTwo = valueTwo; }
  }
  </code></pre>
  
  <p>(In reality these classes are larger)</p>
  
  <p>My only idea is now to create a wrapper class in this was:</p>
  
  <pre><code>public class SomethingWrapper {
  
      private SomethingA someA;
      private SomethingB someB;
  
      public SomethingWrapper(SomethingA someA) {
          //null check..
          this.someA = someA;
      }
  
      public SomethingWrapper(SomethingB someB) {
          //null check..
          this.someB = someB;
      }
  
      public String getValueOne() {
          if (this.someA != null) {
              return this.someA.getValueOne();
          } else {
              return this.someB.getValueOne();
          }
      }
  
      public void setValueOne(String valueOne) {
          if (this.someA != null) {
              this.someA.setValueOne(valueOne);
          } else {
              this.someB.setValueOne(valueOne);
          }
      }
  
      public String getValueTwo() {
          if (this.someA != null) {
              return this.someA.getValueTwo();
          } else {
              return this.someB.getValueTwo();
          }
      }
  
      public void setValueTwo(String valueTwo) {
          if (this.someA != null) {
              this.someA.setValueTwo(valueTwo);
          } else {
              this.someB.setValueTwo(valueTwo);
          }
      }
  } 
  </code></pre>
  
  <p>But I'm not realy satisfied with this solution. Is there any better / more elegant way to solve this problem?</p>