digitalmars.D.learn - Extending an interface or class outside of it
- Frustrated (6/6) Nov 25 2013 I have some type of automatically generated interface using a
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (11/17) Nov 25 2013 Just inherit from it:
- Frustrated (5/29) Nov 25 2013 No, this is not the way. I am creating the interface and need to
- Frustrated (3/36) Nov 25 2013 If it was not generated I could just easily add directly to the
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (14/45) Nov 25 2013 I can be very thick sometimes. :) How about changing the names of the
- Frustrated (8/58) Nov 25 2013 This may work, even though it pollutes the namespace. Probably
- Jonathan M Davis (9/18) Nov 25 2013 No. All members of a class or interface must be declared inside that cla...
- Jacob Carlborg (5/10) Nov 25 2013 Since you're generating the interface in the first place, can't you
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?
Nov 25 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
Nov 25 2013
On Tuesday, 26 November 2013 at 05:03:45 UTC, Ali Çehreli wrote:On 11/25/2013 04:27 PM, Frustrated wrote: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.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
Nov 25 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:If it was not generated I could just easily add directly to the interface.On 11/25/2013 04:27 PM, Frustrated wrote: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.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
Nov 25 2013
On 11/25/2013 09:11 PM, Frustrated wrote:On Tuesday, 26 November 2013 at 05:03:45 UTC, Ali Çehreli wrote:I can be very thick sometimes. :) How about changing the names of the interfaces: interface LessMyInterface { // ... } interface MyInterface : LessMyInterface { // ... }On 11/25/2013 04:27 PM, Frustrated wrote:No, this is not the way. I am creating the interface and need to add to it only because it is generated.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(); } AliIf I inherit from it then I would have to update all references thatuse theinterface to use the new one.No code needs to be changed. Everybody keeps using MyInterface. Ali
Nov 25 2013
On Tuesday, 26 November 2013 at 06:40:24 UTC, Ali Çehreli wrote:On 11/25/2013 09:11 PM, Frustrated wrote: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 which may seem pointless but with mixins it would definitely solve my problem.On Tuesday, 26 November 2013 at 05:03:45 UTC, Ali Çehreliwrote:a mixin anOn 11/25/2013 04:27 PM, Frustrated wrote:I have some type of automatically generated interface usingMyInterfacewould like to extend them after they are generated: mixin(GenerateMyInterface!(...)); ... <Here I would like to add some members/methods toto add toNo, this is not the way. I am creating the interface and needwhich was generated above> ... Is this at all possible?Just inherit from it: interface MyInterface { void foo(); } interface EvenMoreMyInterface : MyInterface { void bar(); } Aliit 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 allreferences that use theinterface to use the new one.No code needs to be changed. Everybody keeps using MyInterface. Ali
Nov 25 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
Nov 25 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
Nov 25 2013