Thread overview
interface: static functions
Apr 25, 2006
Markus Kranz
Apr 25, 2006
Alberto Simon
April 25, 2006
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


April 25, 2006
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
>
> 


April 25, 2006
> "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