Reputation: 1982
I dont get the whole types + Interfaces model(that replaces classes in other languages). If theres a simple way you could explain what they are about, it will be really appreciated.
Upvotes: 8
Views: 363
Reputation: 91050
Go interfaces are statically checked duck typing.
The difference between pure virtual classes in C++ or interfaces in java is that you don't declare the interface on the class that implements the interface, but on the method that receives the interface.
For example, I can create an interface with a Read
and a Write
method and call it ThingsDustinReadsAndWrites
and have a function called doReadsAndWrites(rr ThingsDustinReadsAndWrites
. That can, in turn, receive a built-in http.ClientConn
which has never heard of my interface, but implements it because it happens to have those methods.
Upvotes: 4
Reputation: 28574
This is a pretty good overview:
http://research.swtch.com/2009/12/go-data-structures-interfaces.html
Upvotes: 5