A common template is to make your own "do" methods final and create protected (abstract) methods for subclasses.
In the superclass
@Before public final void before() { onBefore(); } protected void onBefore() { }
In subclass
protected void onBefore() {
It gives you the best of both worlds:
- a well-known method of redefinition in subclasses;
- redefinition is optional;
- the superclass method is never overestimated;
- the client method is called when the superclass makes a decision, that is, before or after the superclass makes a decision.
It has one drawback - it connects you with one superclass. However, this may not be a problem for your environment.
Robert Munteanu
source share