www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Interface inheritance

reply GGB <ggb.dfp bolgar.co.uk> writes:
What are the rules regarding one interface (not class, but 
interface) inheriting from another?

Nothing in the documentation seems to refer to interface 
inheritance, only to class inheritance.

I have tried to do some code with this, and the compiler does not 
complain about one interface inhering from another, but it does 
give some strange results when the child interface tries to 
implement an abstract method in the parent interface.

What I am trying to do in structurally like this:

interface I1
{
     abstract x *A();
}

interface I2: I1
{
     final x *A() { ... }
     final int B() { return f(A()); }
}

interface I3: I1
{
     final int C() { return g(A()); }
}

class C1: I3
{
     final x *A() { ... }
}

class C2: I2
{
    // should not need to define A() because that should be 
defined in I2
    // Not allowed to define A() because already defined in I2
}
Sep 05
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Tuesday, 5 September 2017 at 20:15:44 UTC, GGB wrote:
 What are the rules regarding one interface (not class, but 
 interface) inheriting from another?

 Nothing in the documentation seems to refer to interface 
 inheritance, only to class inheritance.

 I have tried to do some code with this, and the compiler does 
 not complain about one interface inhering from another, but it 
 does give some strange results when the child interface tries 
 to implement an abstract method in the parent interface.
This is related to Issue 2538: https://issues.dlang.org/show_bug.cgi?id=2538 The spec has more information on interfaces here https://dlang.org/spec/interface.html
Sep 05
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Tuesday, 5 September 2017 at 21:44:07 UTC, jmh530 wrote:
 This is related to Issue 2538:
 https://issues.dlang.org/show_bug.cgi?id=2538

 The spec has more information on interfaces here
 https://dlang.org/spec/interface.html
And here is a simpler example: interface I1 { void A(); } interface I2: I1 { final void A() { } } class B: I2 { //It is an error to declare this class either with A or without it }
Sep 05
parent GGB <ggb.dfp bolgar.co.uk> writes:
On Tuesday, 5 September 2017 at 21:45:51 UTC, jmh530 wrote:
 On Tuesday, 5 September 2017 at 21:44:07 UTC, jmh530 wrote:
 This is related to Issue 2538:
 https://issues.dlang.org/show_bug.cgi?id=2538

 The spec has more information on interfaces here
 https://dlang.org/spec/interface.html
And here is a simpler example: interface I1 { void A(); } interface I2: I1 { final void A() { } } class B: I2 { //It is an error to declare this class either with A or without it }
Thanks, I think that explains it, although neither the documentation nor the compiler messages make things clear.
Sep 05