Re: why is multiple inheritance not implemented in java?
Wildemar Wildenburger wrote:
To make my point (with a hypothetical example):
class MyWidget extends Widget
extends Moveable
extends Hideable
extends Detachable
extends Skinable
extends Favorable
extends GenerallyUseful {
...
}
MyWidget would have all sorts of useful features "out of the box",
merely by subclassing. Additional getters, setters and delegators would
just confuse me when reading the code. At the very least they would
produce a lot of lines that I would have to sift though in order for me
to categorize them as "trivial".
Depends on what you mean by "additional". Anyway, this is possible with
interfaces and a bit of extra verbosity (compared to C++), however that
verbosity pays for itself by helping future maintainers see what's happening
and by enforcing various compile-time checks:
public class AbstractWidget implements Widget, Movable, Hidable, Detachable,
Skinnable, Favorable, GenerallyUseful
{
}
public class MyWidget extends AbstractWidget
{
}
Now 'MyWidget' will "have all sorts of useful features 'out of the box',
merely by subclassing", with the additional guarantee that the default
implementations are Widgetish, and not, for example, Mammalian ('Mammal' being
another class that implements 'Skinnable').
--
Lew