what is a usage pattern for "static" in an interface?

Jonathan M Davis jmdavisProg at gmx.com
Fri Feb 3 04:00:34 PST 2012


On Friday, February 03, 2012 11:40:53 Paulo Pinto wrote:
> From OO design it does not make any sense. I was even't aware that this is
> possible in D.
> 
> Static methods are intented to be used as what is commonly known as class
> methods in Smalltalk. Methods
> that are attached to the class class, usually known as metaclass. These
> methods are then transversal to
> all instances of a given class and are called by ClassName.Method() .

That's not generally true of languages such as Java, C#, and D. static 
functions on classes are like any other non-member functions. It's just that 
they're on the class rather than free functions. Usually, they're put there 
because what they do relates to the class. That same idea applies equally to 
interfaces. Java and C# probably don't do that because they don't allow 
function definitions of any kind of interfaces.

> Interfaces don't have implementations per se, they only describe a set of
> funcionalities that any implementing
> class is obliged to provide. Hence there is no direct implementation and no
> difference between instances and
> metaclasses.

D interfaces _do_ allow for function implementations under certain 
circumstances.

- Jonathan M Davis


More information about the Digitalmars-d mailing list