← Go Programming learning pathGo Programming · Module 6 of 10
Interfaces
Write flexible code with implicit interfaces.
📖 Key ideas
- An interface lists method signatures: type Shape interface { Area() float64 }.
- Types implement interfaces implicitly by having the methods.
- Small interfaces are idiomatic: io.Reader, fmt.Stringer.
- Empty interface any holds any value.
- Type switches inspect the concrete type.
💡 Real-life example: Go interfaces are job descriptions: anyone who can do the tasks gets the job, no application form needed.
InterfaceSet of method signatures
Implicit implementationNo implements keyword needed
anyAlias for interface{}
Type switchswitch on a value's type