Understanding Go interfaces, how they work and how to use them
Polyglot developer with an obsession for modularity
Understanding Go interfaces, how they work and how to use them
How interfaces work
Precise definition of interface type syntax and behaviour
Helps to understand how interfaces are implemented under the hood, including the infamous nil gotcha
The tour provides a simple hands on introduction to interfaces, and also covers the nil gotcha
Behavioural subtyping is the concept underlying interface types in Go.
In Go only interfaces can be subtypes, and an interface A is a subtype of interface B if and only if the method set of A is super set of the method set of B. However, this principle runs deeper - interfaces only assert things about the types of the methods in question, but in order to make good use of this, the behaviours of the methods may differ, but must to be compatible from the point of view of the caller.
Dave Cheney's excellent post/talk (link to video within) on how to apply SOLID design in Go provides a practical and principled approach to using interfaces effectively in Go. The L in SOLID stands for Liskov Substitution Principle.