www.digitalmars.com         C & C++   DMDScript  

D - Re: New (?) Interface semantics

Why not have an 'overide' keyword so you can explicitly state when you want
the derived class function to overide the base class function?

chris

 "Walter" <walter digitalmars.com> wrote in message
 news:anf6fl$1aj0$1 digitaldaemon.com...
 I hear you. You might be right. Let's let things percolate a bit and
 see. -Walter

 "Patrick Down" <pat codemoon.com> wrote in message
 news:Xns929B69618134Dpatcodemooncom 63.105.9.61...
 If the D docs are correct, I don't like
 the way interfaces are now implemented.

 I have some general issues with them but
 the thing that I think is a big issue
 is this...

   B b = new B();
   b.foo();    // returns 2
   D d = (D) b;
   d.foo();    // returns 2
   A a = (A) b;
   D d2 = (D) a;
   // REALLY BIG PROBLEM FOR ME HERE!!!
   d2.foo();   // returns 1, because it uses A's D, not B's D

 There are places in my code that I keep arrays of base classes.
 I act on interfaces of these base classes with the expectation
 that they use the most derived interface for that class.

 The only way I can see around this problem now is to do this:


 interface D
 {
     int foo();
 }

 class A : D
 {
     int foo() { return 1; }

     D getDInterface() { return (D)this; }
 }

 class B : A, D
 {
     int foo() { return 2; }

     D getDInterface() { return (D)this; }
 }

 Now use getDInterface() on the base class to get
 the correct interface.



Oct 03 2002