This question is an extension of the following question: Require override of method to call super
I want all subclasses of my superclass to add to the implementation of their parent's update()
method. Since this isn't possible in Java, this is my alternative:
public class MySuperClass{
public final void update{
// common updates for all classes implementing mySuperClass
updateSub0();
}
protected void updateSub0{
// method for next subclass to override
}
}
public class SubClass0 extends mySuperClass{
@Override
protected void updateSub0{
// common updates for all classes implementing subClass0
}
protected void updateSub1{
// method for next subclass to override
}
}
public class SubClass1 extends SubClass0{
@Override
protected void updateSub1{
// common updates for all classes implementing subClass1
}
protected void updateSub0{
// method for next subclass to override
}
}
...
Would this method be considered inappropriate? And if so, could you explain?
Any additional suggestion would also be greatly appreciated.
Additional Info
Since I'm asking for suggestions, I'll try to provide some more information. Basically, I'm working on a system where the entire screen is made up of planes (surfaces). Now, every type of plane has a position, a size and a target position (for smooth repositioning), so the Plane
class (mySuperClass
from the question), would update the position in its update
method.
For planes that are press-able by the user, I extend Plane
with PlanePressable
(SubClass0
from the question). As well as a position, a size, and a target position, PlanePressable
's would have an offset field that stores information on how much it has been pressed. So, as well as updating the position, PlanePressable
's would need to update offset, hence the updateSub0
method.