View mode: basic / threaded / horizontal-split · Log in · Help
February 03, 2012
what is a usage pattern for "static" in an interface?
like:

public interface test
{
  public static void blub();
}

static class test_static: test
{
  private static void blub()
  {
     int i = 10;
  }
}

int main()
{
  test_static.blub();

  return 0;
}

any idea why static could makes sense in an interface? any example?

another thing:

why can i public "blub" in the interface and private it in the class?
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
> any idea why static could makes sense in an interface? any example?

The same reason it makes sense in a class. I don't see any difference.

- Jonathan M Davis
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 08:40, schrieb Jonathan M Davis:
> On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
>>  any idea why static could makes sense in an interface? any example?
>
> The same reason it makes sense in a class. I don't see any difference.

that also my first thought - but why do c#, java (and c++) don't allow it?

and what about the public private thing in my example?
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
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() .

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 seem then to provide a mechanism where implementing classes are 
forced to implement static methods,
but since when calling interface methods the form is always 
Interface.Method(), what is the added benefict to force
static method implementations?

Which use cases have lead to such decision?

--
Paulo

"Jonathan M Davis"  wrote in message 
news:mailman.298.1328254901.25230.digitalmars-d@puremagic.com...

On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
> any idea why static could makes sense in an interface? any example?

The same reason it makes sense in a class. I don't see any difference.

- Jonathan M Davis
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Le 03/02/2012 11:40, Paulo Pinto a écrit :
>  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() .
>
> 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 seem then to provide a mechanism where implementing classes
> are forced to implement static methods,
> but since when calling interface methods the form is always
> Interface.Method(), what is the added benefict to force
> static method implementations?
>
> Which use cases have lead to such decision?
>
> --
> Paulo
>

I think this is collateral effet of the qualifier policy of D. For me, 
this doesn't make any sense too, and it is a strong +1 for not allowing 
that.

This is misleading for beginners.
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
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
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
On Friday, February 03, 2012 09:03:21 dennis luehring wrote:
> Am 03.02.2012 08:40, schrieb Jonathan M Davis:
> > On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
> >>  any idea why static could makes sense in an interface? any example?
> > 
> > The same reason it makes sense in a class. I don't see any difference.
> 
> that also my first thought - but why do c#, java (and c++) don't allow it?

C++ doesn't have interfaces, and C# and Java don't allow function 
implementations of any kind on interfaces. The same is not true for D.

> and what about the public private thing in my example?

It looks like a bug.

- Jonathan M Davis
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 13:02, schrieb Jonathan M Davis:
> C++ doesn't have interfaces, and C# and Java don't allow function
> implementations of any kind on interfaces. The same is not true for D.

but as you can see in my example - my static function isn't implemented 
in the interface scope

interface test
{
  static void blub(); <----
}

there is no example of an not implemented static in a interface
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 13:10, schrieb dennis luehring:
> Am 03.02.2012 13:02, schrieb Jonathan M Davis:
>>  C++ doesn't have interfaces, and C# and Java don't allow function
>>  implementations of any kind on interfaces. The same is not true for D.
>
> but as you can see in my example - my static function isn't implemented
> in the interface scope
>
> interface test
> {
>     static void blub();<----
> }
>
> there is no example of an not implemented static in a interface
>
>

i think should file an bug report for both
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
On 02/03/2012 04:00 AM, Jonathan M Davis wrote:
> D interfaces_do_  allow for function implementations under certain
> circumstances.
>
> - Jonathan M Davis

A code snippet please.
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home