I'm trying to come up with a complete answer to:
"why/when use an abstract class rather than an interface."
and looking for verification/suggestions on the following.
An answer to this is,
"to provide the implementation for some of it. Before the concrete classes come in to define the specific types, an abstract class, typically right below an interface in the inheritance hierarchy (as in many of its examples in the Java APIs) implements and pins down some common aspects of the structure that interface defines.
Another good reason to use an abstract class is that there is a clear logical hierarchy among the types. Abstract class has the use to organize that hierarchy while forcing, by being an abstract class rather than a concrete one, the instantiation of objects only on the concrete classes down below in this hierarchy where they are fully defined and thus are meaningful."
Then, in this context, comes the Q:
"since Java 8, interfaces can define default method implementations. Why wouldn't i write default method(s) in the interface instead of an abstract class that implements those method(s)? "
The answer to this would be:
" One reason is: interface methods are all public, field members are all constants (final & public). You may wanna restrict access privileges of methods and/or make them operate on non-constant state.
Another is: a descendant class can call upon the abstract class method(s) by super, while it can not do so on default interface methods. Also, the interface has no constructors to be invoked by the descendants.
The rest of the reasons are the same as those in pre-Java 8 above. "
Other than these above, why would i rather go for an abstract class than an interface especially now that i have the default interface methods since Java 8?
Please note: i've seen Java 8 default methods vs. non-abstract methods in abstract classes and Interface with default methods vs Abstract class in Java 8 along with some other useful discussions. This Q is rather about why chose an abstract class over an interface than the other way round.
TIA.