I’ve been writing a graphics engine for a while now and I keep running into trouble when I try to abstract state handling. Given the engine I’ve written, I can completely implement applyState(State previous) in the State super class (it then uses custom peers to actually apply it). What I want to do is say (using Light as an example) applyState(Light previous), but have everything still coded in State.
One solution I came up with was to have State be declared as
public class State<S extends State<S>>
and then applyState becomes applyState(S previous).
Using Light as an example again, Light would be declared as
public class Light extends State<Light>
However, this solution seems very fragile and clumsy to me. Is there a better way of solving this kind of problem?
Let me know if I need to explain more,
Thanks