Re: Interface inheritance vs Implementation inheritance.
Peter Duniho wrote:
....
Or, looking at the question from another angle, if it's okay to "borrow"
implementation from another class, what does it matter whether it was
borrowed in the form of inheritance or in the form of a new type of
composition that looks just like inheritance?
....
I think the big question is what gets exposed to users of the borrowing
class.
To make this a bit more specific, consider ArrayList. It implements a
series of interfaces. Those describe the general behavior its callers
can depend on: it's a list, it has fast random access, it can be cloned
and serialized, and it has an Iterator.
In addition, it extends AbstractList. That seems to me to be part of its
implementation, and not something I would use in my code. And yet, a
class outside java.util could declare:
AbstractList<String> someList = new ArrayList<String>();
It might be advantageous to split AbstractList, for example to provide
different implementations depending on whether the list has fast random
access. That cannot be done, because of the public nature of the uses of
AbstractList.
Patricia