To a certain extent, it is a matter of style.
This is common practice , but there are people who tell you that any method should not have more than one implementation. These people claim that several implementations in the inheritance hierarchy lead to complex code debugging, because you have to be extremely careful to determine which version of such a method is actually called.
And when such methods are used mainly in other ways, you can easily lose the big picture — it suddenly becomes difficult to foresee what some code is doing — due to heavy overriding in some subclasses.
Key value for understanding: the "single" @Override for some foo() method in class X is great and common, good practice. But overriding the same foo() again in subclasses of X - this can quickly lead to all the problems.
In other words: the re-introduction of non-abstract methods must be done carefully. If this makes it difficult to understand the code, then look for other solutions. For example: a base class having a fixed (finite) method that does things - and this method calls other abstract methods to do its job. Example:
public abstract class Base { public final int doSomething() { String tmp = foo(); int result = bar(tmp); return result * result; } public abstract String foo(); public abstract int bar(String str);
As it is written: here you can see that the implementation is "fixed" because doSomething() is final, but the required "ingredients" can (should) be redefined in each subclass.
Ghostcat
source share