I am creating a multiple wrappers/layers API in Java that go like this
public class Layer1<T extends Layer1>
public class Layer2<T extends Layer2> extends Layer1<Layer2>
public class Layer3 extends Layer2<Layer3>
with methods like public T sees(){ return (T) this;}
within each layer
What is the correct way for the above structure to work as to be able to maintain the original object's, we start the chain with, type throughout the call.
Aka the following to be feasible: 3rdLayerObject.1stLayerMethod().2ndLayerMethod();
where the 1stLayer method call returns a 1st layer object(instead of subclass 3rd) and therefore calling a 2nd layer method returns an error.
Why the API is structured as such:
1st layer has only the methods that apply to all situations
2nd layer has client specific methods that either override the 1st wrapper's basic implementations or are entirely new
3rd layer has project specific methods that are mainly new methods used only by this project.
Of course, if you think the above structure is flawed and there is another pattern/structure to use to organize this more effectively I am open to any and all ideas.