title: java: puzzle about generics structure
body: <p>I have a puzzle about the creation of a structure: an interface Transform that represent a general physical transformation, and a class PoincareTransform that represent a specific type of transformation. I would like to do a thing like this</p>
  
  <pre><code>public interface Transform {
     public Transform compose(Transform t);
  }
  
  public class PoincareTransform implements Transform {
     private Matrix matrix;
     public Transform compose(Transform t) {
     ...
     }
  }
  </code></pre>
  
  <p>but I would like that method compose(Transform T) to take only PoicareTransform because is necessary to have a matrix to compose with. A possible solution is using generics</p>
  
  <pre><code>public interface Transform&lt;T extends Transform&lt;T&gt;&gt; {
     public T compose(T t);
  }
  
  public class PoincareTransform implements Transform&lt;PoincareTransform&gt; {
     private Matrix matrix;
     public PoincareTransform compose(PoincareTransform t) {
     ...
     }
  }
  </code></pre>
  
  <p>but this is not satisfactory because is not conceptually clean, elegant and there are some trouble again: PoincareTransform subclasses have now the same problem as before. Also, with this definition, I have generics all around my project!</p>
  
  <p>I'm conceptually wrong? How could I build a structure like this that I have in mind?</p>