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
public interface Transform {
public Transform compose(Transform t);
}
public class PoincareTransform implements Transform {
private Matrix matrix;
public Transform compose(Transform t) {
...
}
}
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
public interface Transform<T extends Transform<T>> {
public T compose(T t);
}
public class PoincareTransform implements Transform<PoincareTransform> {
private Matrix matrix;
public PoincareTransform compose(PoincareTransform t) {
...
}
}
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!
I'm conceptually wrong? How could I build a structure like this that I have in mind?