www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implementing multiple inheritance in D

reply kenji hara <k.hara.pg gmail.com> writes:
I have tried to implement multiple inheritance in D.

My first idea is binary inheritance tree with using alias this, but
current dmd doesn't look alias this on superclasses.
So I have tried to fix this behavior.
-> https://github.com/9rnsr/dmd/tree/MultiInheritPatch

Result:
-> http://ideone.com/iD4JE

Some issues:
- Calling constructors of superclasses syntax.
- Object layout (share __monitor object? reduce overhead?)

Do you think?
May 09 2011
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 5/9/11 12:43 PM, kenji hara wrote:
 I have tried to implement multiple inheritance in D.

 My first idea is binary inheritance tree with using alias this, but
 current dmd doesn't look alias this on superclasses.
 So I have tried to fix this behavior.
 ->  https://github.com/9rnsr/dmd/tree/MultiInheritPatch

 Result:
 ->  http://ideone.com/iD4JE

 Some issues:
 - Calling constructors of superclasses syntax.
 - Object layout (share __monitor object? reduce overhead?)

 Do you think?
This is very interesting. I don't understand the example though (some is commented out, some is in, and I'm unclear on what didn't use to work and what works). Also I can't find the important commits in your branch, so it may be best to organize those as one pull request for the dmd mainline. Could you please provide more detail on what you fixed and what the resulting context is? Thanks, Andrei
May 09 2011
parent kenji hara <k.hara.pg gmail.com> writes:
Thanks for your comment.

 Could you please provide more detail on what you fixed and what the
 resulting context is?
I posted 'Issue 5973 - alias this is not considered with superclass lookup' for dmd issue. http://d.puremagic.com/issues/show_bug.cgi?id=5973 The issue is that dmd does not consider alias this in super classes on member lookup. More clean code: https://github.com/9rnsr/scrap/blob/master/multiInherit.d New feature: - Support class that have explicit constructor. See X.this code with -version=ExplicitCtor. May not support: - Diamond inheritance Kenji Hara
May 10 2011
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-05-09 19:43, kenji hara wrote:
 I have tried to implement multiple inheritance in D.

 My first idea is binary inheritance tree with using alias this, but
 current dmd doesn't look alias this on superclasses.
 So I have tried to fix this behavior.
 ->  https://github.com/9rnsr/dmd/tree/MultiInheritPatch

 Result:
 ->  http://ideone.com/iD4JE

 Some issues:
 - Calling constructors of superclasses syntax.
 - Object layout (share __monitor object? reduce overhead?)

 Do you think?
Why not emulate it with interfaces and template mixins? -- /Jacob Carlborg
May 09 2011
parent reply kenji hara <k.hara.pg gmail.com> writes:
 Why not emulate it with interfaces and template mixins?
Interfaces? I don't understand what you mean. So please give me a example code. Kenji Hara
May 10 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-05-10 10:14, kenji hara wrote:
 Why not emulate it with interfaces and template mixins?
Interfaces? I don't understand what you mean. So please give me a example code. Kenji Hara
interface Super { void foo (); } template SuperImpl { void foo () { /* do something */ } } class Sub : Super { mixin SuperImpl; void bar () { /* do something else */ } } This might not be the best solution, it won't work with existing class hierarchies. I've actually tried this now and it won't work, you cannot override the methods coming from the mixin. -- /Jacob Carlborg
May 10 2011