Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
December 23, 2004 interfaces and static methods | ||||
---|---|---|---|---|
| ||||
The following code does not compile, is it supposed?
interface ITest {
static void func();
}
class Test : ITest {
static void func() {
}
}
int main(char[][] args) {
ITest t = new Test;
t.func();
}
--
Miguel Ferreira Simoes
|
December 23, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Miguel Ferreira Simões Attachments: | Added to DStress as http://svn.kuehne.cn/dstress/compile/interface_08.d http://svn.kuehne.cn/dstress/compile/interface_09.d http://svn.kuehne.cn/dstress/run/interface_10.d http://svn.kuehne.cn/dstress/run/interface_11.d Thomas |
December 23, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Miguel Ferreira Simões | I dont think its supposed to. If so I would imagine the body in the interface ( but I dont think interfaces should have static methods ). Also where can I your NN code again ? Perhaps you could set it up on dsource ? Thanks, Charlie "Miguel Ferreira Simões" <Kobold@netcabo.pt> wrote in message news:cqe7j0$2fl3$1@digitaldaemon.com... > > The following code does not compile, is it supposed? > > interface ITest { > static void func(); > } > > class Test : ITest { > static void func() { > > } > } > int main(char[][] args) { > ITest t = new Test; > t.func(); > } > > -- > Miguel Ferreira Simoes > > |
December 23, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles | I think the problem is still there if i subsitute the interface for an abstract class. You said you are against static methods in interfaces. Why? Right now my homepage is down. But I will re-activate it a near future. If you want I can e-mail you a copy of my NN code (the project is temporarily halted until February, because I do not have time). Miguel Ferreira Simoes |
December 24, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Miguel Ferreira Simões | > You said you are against static methods in interfaces. Why? I see them as purley an abstraction , a contract saying 'you must implement these' , as opposed to a structure or something that would contain code or variables. I usually do : interface IFoo {} class AbstractFoo : IFoo { static void bar() {} ; int inheritedVariable; } Have all classes that need IFoo inherit from AbstractFoo. Does java / C# allow static methods in interfaces ? > If you want I can e-mail you a copy of my NN code Please :). greenelephant.charles@gmail.com Also do you know a good online source about neural networks ( the examples Ive seen dont incorporate noise / cost / regularization ). Thanks, Charlie "Miguel Ferreira Simões" <Kobold@netcabo.pt> wrote in message news:cqfjgb$12n5$1@digitaldaemon.com... > I think the problem is still there if i subsitute the interface for an abstract class. > > You said you are against static methods in interfaces. Why? > > Right now my homepage is down. But I will re-activate it a near future. If you want I can e-mail you a copy of my NN code (the project is temporarily halted until February, because I do not have time). > > Miguel Ferreira Simoes > > |
December 24, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles | Charles wrote:
>>You said you are against static methods in interfaces. Why?
>
>
> I see them as purley an abstraction , a contract saying 'you must implement
> these' , as opposed to a structure or something that would contain code or
> variables.
>
> I usually do :
>
> interface IFoo {}
> class AbstractFoo : IFoo { static void bar() {} ; int inheritedVariable; }
>
> Have all classes that need IFoo inherit from AbstractFoo. Does java / C#
> allow static methods in interfaces ?
>
Yes both Java and .NET do, however, I think that is an ugly method. For D it isn't necessary due to the fact that it also supports pure procedural development (hibrid development). Therefor a D source file can declare methods right into the module body.
Abstract classes are not meant to interface, but are mostly used for predefined functionality, which may or may not depend on extra methods needed by one or more already specified methods.
Interfaces are not meant for abstraction in the manner of making code more reusable (as abstract classes do), but abstraction in the manner of making components more reusable. This also makes it possible for interfaces to develop components using a modulair approach (using Shared Libraries, COM, CORBA, etcetera) and therefor behave (more) dynamic.
Regards,
Sjoerd
|
December 25, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles | I am not saying intefaces should have static methods: that question is controversial. Nevertheless, in my humble opinion, abstract classes should support abstract static methods. It compiles. But gives me a link error when I try to use the static method: Error 42: Symbol Undefined _D6source8graphics5image11ImageLoader11ImageLoader10 extensionsFZAAa -- errorlevel 1 Miguel Ferreira Simoes |
December 27, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Miguel Ferreira Simões | "Miguel Ferreira Simões" <Kobold@netcabo.pt> wrote in message news:cqji9h$26ro$1@digitaldaemon.com... > I am not saying intefaces should have static methods: that question is > controversial. > Nevertheless, in my humble opinion, abstract classes should support abstract > static methods. > > It compiles. But gives me a link error when I try to use the static method: > > Error 42: Symbol Undefined > _D6source8graphics5image11ImageLoader11ImageLoader10 > extensionsFZAAa > -- errorlevel 1 The trouble is it cannot know which function to call without a 'this' pointer, and once there is a 'this' pointer, it isn't a static method anymore! |
December 27, 2004 Re: interfaces and static methods | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter schrieb in cqoj5a$sle$2@digitaldaemon.com. > > "Miguel Ferreira Simões" <Kobold@netcabo.pt> wrote in message > > news:cqji9h$26ro$1@digitaldaemon.com... > > I am not saying intefaces should have static methods: that question is > > controversial. > > Nevertheless, in my humble opinion, abstract classes should support > > abstract static methods. > > > > It compiles. But gives me a link error when I try to use the static method: > > > > Error 42: Symbol Undefined > > _D6source8graphics5image11ImageLoader11ImageLoader10 > > extensionsFZAAa > > -- errorlevel 1 > > The trouble is it cannot know which function to call without a 'this' pointer, and once there is a 'this' pointer, it isn't a static method anymore! Couldn't this be done via the "type pointer"? 1) If there is a 'this' pointer, use the current lookup. 2) Without a 'this' pointer query the type information for static functions. Thomas |
Copyright © 1999-2021 by the D Language Foundation