title: Add a layer of mapping on a child class
body: <p>I am trying to write a class that works as a type of map. The children of this class have layers of mapping on top of basic functionality. Something like the below: </p>
  
  <pre><code>public interface MyMap&lt;K, V&gt; {
    public V get(K key);
  }
  
  public interface Client&lt;K, V&gt; {
    public V fetch(K key);
  }
  
  public class ComplexKey&lt;T&gt; {
  
    private T _key;
  
    public ComplexKey(T key) {
      _key = key;
    }
  
    T getKey() {
      return _key;
    }
  }
  
  public class BasicMyMap&lt;K, V&gt; implements MyMap&lt;K, V&gt; {
  
    private final Client&lt;K, V&gt; _client;
  
    public BasicMyMap(Client&lt;K, V&gt; client) {
      _client = client;
    }
    @Override
    public V get(K key) {
      return _client.fetch(key);
    }
  }
  
  /**
   *
   * @param &lt;MK&gt; mapped key
   * @param &lt;K&gt; key
   * @param &lt;V&gt; value
   */
  public class ComplexKeyMyMap&lt;MK extends ComplexKey, K, V&gt; implements BasicMyMap&lt;MK, V&gt; {
  
    private Function&lt;K, MK&gt; _mapper;
  
    public ComplexKeyMyMap(Client&lt;MK, V&gt; client, Function&lt;K, MK&gt; mapper) {
      super(client);
      _mapper = mapper;
    }
  
    public V get(K rawKey) {
      return super.get(_mapper.apply(rawKey));
    }
  }
  
  public static void main(String[] args) {
    BasicMyMap&lt;String, String&gt; basicMyMap = new BasicMyMap&lt;&gt;(key -&gt; "success");
    assert "success".equals(basicMyMap.get("testing"));
  
    ComplexKeyMyMap&lt;ComplexKey, String, String&gt; complexKeyMyMap = new ComplexKeyMyMap&lt;&gt;(key -&gt; "success", (Function&lt;Object, ComplexKey&gt;) ComplexKey::new);
    assert "success".equals(complexKeyMyMap.get("testing"));
  }
  </code></pre>
  
  <p>In addition to the key mapping, I would like to add a layer for mapping the value that is returned as well. </p>
  
  <p>So question is: </p>
  
  <ol>
  <li>What is the common approach to this problem? I have encountered this pattern multiple times and have not found a great solution. </li>
  <li>How can I achieve this such that the users of these classes can just rely on the <code>MyMap</code> interface definition. </li>
  </ol>
  
  <p>Thanks for the help.</p>