Thread overview
Extending an interface or class outside of it
Nov 26, 2013
Frustrated
Nov 26, 2013
Ali Çehreli
Nov 26, 2013
Frustrated
Nov 26, 2013
Frustrated
Nov 26, 2013
Ali Çehreli
Nov 26, 2013
Frustrated
Nov 26, 2013
Jonathan M Davis
Nov 26, 2013
Jacob Carlborg
November 26, 2013
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?


November 26, 2013
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

November 26, 2013
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. If I inherit from it then I would have to update all references that use the interface to use the new one.
November 26, 2013
On Tuesday, 26 November 2013 at 05:12:00 UTC, 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. If I inherit from it then I would have to update all references that use the interface to use the new one.

If it was not generated I could just easily add directly to the interface.
November 26, 2013
On Tuesday, November 26, 2013 01:27:49 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?

No. All members of a class or interface must be declared inside that class or interface. It's possible to define them elsewhere (albeit a bit of a pain), but it's not possible to declare them elsewhere. A class, struct, or interface declaration cannot be broken up. So, if you're generating a class or interface and mixing it in, you have to mix the entire thing in at once. You could build what you're mixing in from multiple mixins (especially if you're using string mixins), but once you create the interface declaration, it is what it is.

- Jonathan M Davis
November 26, 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

November 26, 2013
On 2013-11-26 01:27, 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> ...

Since you're generating the interface in the first place, can't you generate it correctly to begin with.

-- 
/Jacob Carlborg
November 26, 2013
On Tuesday, 26 November 2013 at 06:40:24 UTC, Ali Çehreli wrote:
> 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

This may work, even though it pollutes the namespace. Probably not a big deal though, better than having to completely generate the interface as a string(which offers very little compilation support(syntax errors, etc). It would be nice to have partial classes similar to C# even if they have to be in the same module which may seem pointless but with mixins it would definitely solve my problem.