Amidst defining the hierarchy, firstly, one can think to embed the abstract method(behavior) in abstract class
only because the derive concrete class possess that behavior as core behavior with it's specific implementation, secondly, one can think to embed the abstract method(behavior) in interface
only because derived concrete class possess that behavior as non-core behavior(peripheral) having it's specific implementation.
As I would not rely on this example which supports above point, below are the two references, I would rely on.
1) First reference that supports this point:
Interfaces are ideal for defining mixins. Loosely speaking, a mixin is a type that a class can implement in addition to its "primary type" to declare that it provides some optional behavior. For example,
Comparable
is a mixing interface that allows a class to declare that its instances are ordered with respect to other mutually comparable objects. Such an interface is called a mixin because it allows the optional functionality to be "mixed in" to the type's primary functionality. Abstract classes can't be sued to define mixins for the same reason that they can't be retrofitted onto existing classes: a class cannot have more than one parent, and there is no reasonable place in the class hierarchy to insert a mixin.
2) Second reference that support this point:
In UML sketch, the relation between interface
model and concrete class
model is named Realisation
, where as, the relation between abstract class
model and concrete class
model is named is-a
relation. Here is-a
can be told, when concrete class
has core behavior unlike realisation
relation.
So, with these two references, It looks list<E>
and Collection<E>
are abstract class
but not interface
.
With this above explanation, I would like to understand,
Why Collection<E>
and List<E>
is designed to be interface
in java.util
package?
Is my understanding correct?
Queue
as well? ALinkedList
is both, but it can't have double inheritance!What specific behaviour would an array-backed list and a linked list have that is the same in implementation?
, am not sure, why the implementation of array-backed list and linked list will be same(for example, insertFront() say)?, they will be different but for same behaviour name(i.e., insertFront()). for your second question: Yes,Queue
should be an abstract class` if it has its own core behaviour. ifLinkedList
is trying to inherit core behaviours of both super typesList
andQueue
then that is meaningless.