www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - interface: static functions

reply Markus Kranz <Markus_member pathlink.com> writes:
Is there a reason, one can define static functions in interfaces,
but 'implementing' classes don't really have to implement them?

interface A {
static void doIt();
}

class B : A {
}

is valid dmd 0.154 (linux) code.

Regards,
Markus
Apr 25 2006
parent reply "Alberto Simon" <lugaidster gmail.com> writes:
It is confusing since an interface by definition is a contract (I'm not that 
familiar with D but am with interfaces)  would say it is a bug, but I can't 
confirm it.

Regards,
Alberto Simon

"Markus Kranz" <Markus_member pathlink.com> escribió en el mensaje 
news:e2lqru$jgq$1 digitaldaemon.com...
 Is there a reason, one can define static functions in interfaces,
 but 'implementing' classes don't really have to implement them?

 interface A {
 static void doIt();
 }

 class B : A {
 }

 is valid dmd 0.154 (linux) code.

 Regards,
 Markus

 
Apr 25 2006
parent =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
 "Markus Kranz" <Markus_member pathlink.com> escribió en el mensaje 
 news:e2lqru$jgq$1 digitaldaemon.com...
 Is there a reason, one can define static functions in interfaces,
 but 'implementing' classes don't really have to implement them?

 interface A {
 static void doIt();
 }

 class B : A {
 }

 is valid dmd 0.154 (linux) code.
Alberto Simon wrote:
 It is confusing since an interface by definition is a contract (I'm not that 
 familiar with D but am with interfaces)  would say it is a bug, but I can't 
 confirm it.
I can confirm it. It has been that way for a long time. D interfaces should be wholly reimplemented. There are some serious limitations and problems now. One other funny thing are protection attributes: SuperClass: Identifier Protection Identifier InterfaceClass: Identifier Protection Identifier Protection: private package public export http://www.digitalmars.com/d/class.html I think they are legacy syntax from C++. There is no point in limiting the visibility of interface members. AFAIK they aren't even implemented at the moment, but DMD successfully accepts them. Implementing these would probably break the interface covariance stuff also. -- Jari-Matti
Apr 25 2006