www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - interfaces and static methods

reply "Miguel Ferreira Simões" <Kobold netcabo.pt> writes:
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 
Dec 23 2004
next sibling parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

-----BEGIN PGP SIGNATURE-----

iD8DBQFByzU13w+/yD4P9tIRAmGQAKCRqx5WxmoD8mNdRt4RU9KuVbTcWACeJIM7
WcpvplEMK8FGCMeR2j42+rc=
=1hOt
-----END PGP SIGNATURE-----
Dec 23 2004
prev sibling parent reply "Charles" <no email.com> writes:
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
Dec 23 2004
next sibling parent reply "Miguel Ferreira Simões" <Kobold netcabo.pt> writes:
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
Dec 23 2004
parent reply "Charles" <no email.com> writes:
 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; } 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
Dec 23 2004
parent Sjoerd van Leent <svanleent wanadoo.nl> writes:
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; } 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
Dec 24 2004
prev sibling parent reply "Miguel Ferreira Simões" <Kobold netcabo.pt> writes:
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 
Dec 25 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"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!
Dec 27 2004
parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
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
Dec 27 2004