4 ms·
Good article - this covers the basic OO patterns in Go. I really like the simplicity of the design - objects are just structs and you can define a method for th
by noelherrick 13y ago
Good article - this covers the basic OO patterns in Go. I really like the simplicity of the design - objects are just structs and you can define a method for that object. Coming from C#, it's like every method is an extension method.
The only critique I have is that there's no way to verify that object X implements methods A, B, and C. When I'm using C# or Java, I often use an interface as a test to make sure I've done my work since the code won't compile if a class that extends an interface fails to implement all the methods.
- gmi01 13y agoTo verify that Concrete implements Interface use this: var _ Interface = Concrete{}
- lnmx 13y agoThe compiler will complain if you attempt to assign (or assert) a value to an interface that it cannot fulfill. ex. http://play.golang.org/p/OLTHIXjgy8 http://play.golang.org/p/OLTHIXjgy8
- nathany 13y ago"Compared to duck typing, interfaces are statically checked and documented through their declaration..."