I’ve got an abstract class like this
public abstract Stuff
{
public abstract void doStuff();
}
Several classes are extending Stuff, overriding doStuff(). doStuff() in general performs totally different tasks for each implementation but shares a common part.
Whats the best way to implement this?
I don’t want to write someting like:
public void doStuff()
{
doTheCommonPart();
...
}
in every extending class.
Either:
Place the common code in a
protectedmethod in theStuffclass and call it from each implementation ofdoStuff; orAdd the common code to your abstract
Stuffclass and call another abstract method.E.g. (1)
or (2)