← Go Programming learning path
Go Programming · Module 6 of 10

Interfaces

Write flexible code with implicit interfaces.

📖 Key ideas

  1. An interface lists method signatures: type Shape interface { Area() float64 }.
  2. Types implement interfaces implicitly by having the methods.
  3. Small interfaces are idiomatic: io.Reader, fmt.Stringer.
  4. Empty interface any holds any value.
  5. 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