Multiple inheritance in Java/C#

Hung Jung Lu hungjunglu at yahoo.com
Thu Nov 20 08:48:54 EST 2003


Thomas <pushcold at hotpop.foo> wrote in message news:<pan.2003.11.19.14.55.27.948101 at hotpop.foo>...
> 
> There are pros and cons for MI; I never liked the MI design (e.g.
> because it can lead to nasty bugs, which are really hard to find)
> and prefer C#'s way.

If you use MI to inherit classes and do cascade calls (calling parent
methods with same name, like the case of constructors) up the tree of
inheritance, sure, you get into big mess. But if you use MI as MixIns
without cascade calls, you won't have those nasty bugs. I don't think
I like C# or Java for their lack of MI. You see pairs of
interfaces/implementations all over places, and use
containment+delegation to emulate MI. Things that can be done in a few
lines of code in C++, will be typically multiplied by a factor about 3
when you do them in Java/C#. More over, if you change your interface,
say, just adding one more method, you'll have to make changes all over
places.

> At least, the compiler tells you exactly what to do; in my 
> experience, this leads to very stable applications, even if the
> application gets very large. (If you work with MI, it might happen
> as well that you have to change many classes when you make changes
> to the base classes.)

I think we have different purposes for MI. I use MI for MixIns, not as
real classes, and no cascade calls upstream. The value of MixIns to me
is in their code/action, not in their object/data. I can understand
difficulties when you use MI for object/data. In C++ I can add a new
method in a great-grand-parent class in line, and touch the code only
in two spots: where it is defined, and where it is used. In Java/C#,
it would be hell.

> I hope that C# uses it's chance of being a (IMHO) well designed
> language, which can concentrate now on performance and stability
> issues (and not on implementing new features). Python used to be
> that way, but in the last time, it is developing too fast (IMHO).

I can't speak on how well designed it is. But I do know that both Java
and C# are now adding generic templates. So at least the original
designs were not complete.

Hung Jung




More information about the Python-list mailing list