reddit discussion about Go turns to D again

Matthew Ong ongbp at yahoo.com
Mon May 16 06:54:59 PDT 2011


Hi,

Oh a few more thing that got my interest is how the Go model their data. Not
entirely like how other conventional OO does it. They do NOT
have Object inheritance. But uses interface to some how 'bypass' that.


http://golang.org/doc/effective_go.html

Conversions
...
// this function is now available for the object type Sequence.
func (s Sequence) MyFunction() string {
   //  My Function has access to all the public/internal data of the
   // Sequence here.
}
...
s Sequence;
s.MyFunction(); // now that can be used.

That is some how like JRuby ability to 'add' method into the java final String
class without really touching that API.


Generality
It also >avoids< the need to repeat the documentation on every instance of a
common method.

Interfaces and methods

Since almost anything can have methods attached, almost anything can satisfy an
interface. One illustrative example is in the http package, which defines the
Handler interface. Any object that implements Handler can serve HTTP requests.


It is not just entirely like java interfaces, but java has to somehow, code the
api in a very strange pattern to support this.

Hopefully, does D currently support such ability?

Matthew Ong
ongbp at yahoo.com




More information about the Digitalmars-d mailing list