Extending an interface or class outside of it

Ali Çehreli acehreli at yahoo.com
Mon Nov 25 22:40:23 PST 2013


On 11/25/2013 09:11 PM, Frustrated wrote:

 > On Tuesday, 26 November 2013 at 05:03:45 UTC, Ali Çehreli wrote:
 >> On 11/25/2013 04:27 PM, Frustrated wrote:
 >>> I have some type of automatically generated interface using a mixin an
 >>> would like to extend them after they are generated:
 >>>
 >>>     mixin(GenerateMyInterface!(...));
 >>>
 >>>     ... <Here I would like to add some members/methods to MyInterface
 >>> which was generated above> ...
 >>>
 >>> Is this at all possible?
 >>>
 >>>
 >>
 >> Just inherit from it:
 >>
 >> interface MyInterface
 >> {
 >>     void foo();
 >> }
 >>
 >> interface EvenMoreMyInterface : MyInterface
 >> {
 >>     void bar();
 >> }
 >>
 >> Ali
 >
 > No, this is not the way. I am creating the interface and need to add to
 > it only because it is generated.

I can be very thick sometimes. :) How about changing the names of the 
interfaces:

interface LessMyInterface
{
     // ...
}

interface MyInterface : LessMyInterface
{
     // ...
}

 > If I inherit from it then I would have to update all references that 
use the
 > interface to use the new one.

No code needs to be changed. Everybody keeps using MyInterface.

Ali



More information about the Digitalmars-d-learn mailing list