implicit interface satisfaction
Go's rule that a type meets an interface just by having the right methods, with no implements declaration.
In more detail
The type's author never names the interface, so a consumer can define a small interface after the fact and existing types already fit it. This is what makes fakes for tests cheap. The compiler still checks the methods match wherever the value is used as that interface.
Example
func (Robot) Speak() string { return "ready" } // Robot now satisfies SpeakerRelated terms
- interface — A named set of member signatures that a type promises to implement, with no state of its own.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- test double — Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.
Taught in
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go