Suggestion: Walter Bright, why not to implement multiple inheritance in D?

Arlen Albert Keshabyan arlen.albert at gmail.com
Fri Dec 1 13:56:35 PST 2006


Recently, I've started the subject about multiple inheritance in D. I've got
the answers. But those solutions are not enough suitable for my purposes. Then
I thought, why not to implement the feature which is on demand by programmers
in D? Multiple inheritance is needed indeed just only by seeing the attempts
of programmers to emulate it in D. It means they need it. Multiple inheritance
is really not that bad thing which is supposed to be got rid of. Just a linear
multiple inheritance with possibility to get to the every level of its
hierarchy is enough, I think. Moreover, I'll help to port many useful C++ code
into D much easier than now.

I know two approaches by now, but both are restrictive to feel the freedom of
multiple inheritance.

First approach is excellent, but does not allow you to get as deep as you want
to the class hierarchy (only super's virtual methods are accessible explicitly):

//////////////////////////////////
interface I
{
}

class A(T) : T, I
{
}

class B(T) : T, I
{
}

class C(T) : T, I
{
}

alias C!(B!(A(Object))) D;
////////////////////////////////

Second approach is excellent too, but lacks template merging possibilities and
pointing explicitly which interface function to implement (on name collisions):

//////////////////////////////////////
interface A
{
}

interface B
{
}

interface C
{
}

template A_()
{
}

template B_()
{
}

template C_()
{
}

class D : A, B, C
{
   mixin A_;
   mixin B_;
   mixin C_;
}
////////////////////////////////

Walter, is it a matter of principle not to implement multiple inheritance in
D? If D is the language of practical usage then multiple inheritance must be
considered to implement.
What do you think?



More information about the Digitalmars-d mailing list