Function implementation in interface

The Anh Tran trtheanh at gmail.com
Fri Jan 29 23:53:19 PST 2010


First, i would like to say: thank you.

Second, i would like to have your opinion:
"added static/final function implementations to interfaces"

Could you allow normal function imp to interfaces too? Interface will 
look like c++ struct, but the difference is the way inheritance 
organized, so that diamond shape problem does not exist.

And you could simplify something too. For example: for comparison 
between classes, we just inherit Comparable interface, which has 
implementation of many op<, op>, op<=, op>=, ...

(Well, in fact, this is done in Scala, it is named linearization). :)

For example:

class Biology
{
     ......
}

interface Animal
{
     void eat() { ... }
     void run() { ... }
}

interface Bird
{
     void fly() { ... }
}

class Penguin : Biology, Animal, Bird
{
}

The left most class / interface will be the top super. Each interface 
remain will solve its parent at definition site (line "class Penguin : 
Biology, Animal, Bird")
Result: Penguin -> Bird -> Animal -> Biology.

Details of linearization are in page 52, ScalaRef.
http://www.scala-lang.org/sites/default/files/linuxsoft_archives/docu/files/ScalaReference.pdf

Thanks.



More information about the Digitalmars-d-announce mailing list