www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What is the sub interface?

reply Haruki Shigemori <rayerd.wiz gmail.com> writes:
(1)
interface A {void a();}
interface B : A {}

(2)
interface B {void a();}

If both interfaces of B are the *same* when paying attention to interface B,
I think that the next code is invalid-accept about class C2.
Because class C2 do not have a method "void a(){}".

http://www.digitalmars.com/d/2.0/interface.html
 A reimplemented interface must implement all the interface functions,
it does not inherit them from a super class interface I1 {void a();} interface I2 : I1 {} class C1 : I2 {void a(){}} class C2 : C1, I2 {} // invalid-accept? (dmd 2.026) How do you think about?
Mar 24 2009
parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
Haruki Shigemori escribió:
 (1)
 interface A {void a();}
 interface B : A {}
 
 (2)
 interface B {void a();}
 
 If both interfaces of B are the *same* when paying attention to interface B,
 I think that the next code is invalid-accept about class C2.
 Because class C2 do not have a method "void a(){}".
 
 http://www.digitalmars.com/d/2.0/interface.html
 A reimplemented interface must implement all the interface functions,
it does not inherit them from a super class
I think this last sentence doesn't make any sense at all. Some might consider it an enhancement but I consider it as an issue.
 
 interface I1 {void a();}
 interface I2 : I1 {}
 class C1 : I2 {void a(){}}
 class C2 : C1, I2 {} // invalid-accept? (dmd 2.026)
 
 How do you think about?
You wouldn't have to break your head if implementing an interface meant "having the methods declared in that interface". No error should appear in C2. What's the rationale behind this behaviour?
Mar 24 2009
parent Christopher Wright <dhasenan gmail.com> writes:
Ary Borenszweig wrote:
 You wouldn't have to break your head if implementing an interface meant
 "having the methods declared in that interface". No error should appear
 in C2.
 
 What's the rationale behind this behaviour?
Naming collisions and different library versions. In practice, I suspect this comes up very rarely. An example: module library.something; interface TheInterface { } module mycode.mymodule; class TheBaseClass { void frob () {} } class TheClass : TheBaseClass, TheInterface { } module library.something; interface TheInterface { // hey, that's new void frob (); } module mycode.mymodule; class TheBaseClass { void frob () {} } class TheClass : TheBaseClass, TheInterface { // wait, that frob doesn't do the right thing }
Mar 24 2009