title: Design pattern for converting one model to another
body: <p>I am writing a library in java and I need to convert (map) one model to another and vice versa. What I did was implementing an abstract converter class with 2 generic types, containing convertTo and convertFrom methods, and extended my converters from it.</p>
  <pre><code>public abstract class TypeConverter&lt;MyType, OtherLibType&gt; {
      private final Function&lt;MyType, OtherLibType&gt; fromMyType;
      private final Function&lt;OtherLibType, MyType&gt; fromOtherLibType;
  
      public TypeConverter(final Function&lt;MyType, OtherLibType&gt; fromMyType,
                           final Function&lt;OtherLibType, MyType&gt; fromOtherLibType
      ) {
          this.fromMyType = fromMyType;
          this.fromOtherLibType = fromOtherLibType;
      }
  
      public final OtherLibType convertFromMyType(final MyType myType) {
          return fromMyType.apply(myType);
      }
  
      public final MyType convertFromJspritType(final OtherLibType otherLibType) {
          return fromOtherLibType.apply(otherLibType);
      }
  
  }
  </code></pre>
  <p>But for specific implementations I also may need other objects for converting and I don't know what is the best practice to implement such things. I thought about adapter and facade but they don't seem to match my requirements. Is there a design pattern that I could use for this? Thank you in advance.</p>