By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
So far every function has asked for a concrete type: an int, an Expense, a []Expense. That works until you want one function to handle several kinds of value that share something in common.
An interface describes behaviour. It is a list of method signatures with no bodies. Any type that has all of those methods satisfies the interface, and can be used wherever the interface is expected. The best part is that Go checks this for you, and the type never has to mention the interface at all. There is no implements keyword to forget.
Here is one function that prints a list of anything that can describe itself. The Expense and Category types are unrelated, but both have Describe() string, so both satisfy Describer.
package main
import "fmt"
// Describer is a small interface: one method, one job.
type Describer interface {
Describe() string
}
type Expense struct {
Description string
Cents int
}
func (e Expense) Describe() string {
return fmt.Sprintf("%s (%d cents)", e.Description, e.Cents)
}
type Category struct {
Name string
}
func (c Category) Describe() string {
return "category: " + c.Name
}
// describeAll only knows about behaviour, not concrete types.
func describeAll(items []Describer) {
for _, item := range items {
fmt.Println(item.Describe())
}
}
func main() {
items := []Describer{
Expense{Description: "Coffee", Cents: 450},
Category{Name: "Food"},
}
describeAll(items)
}describeAll never mentions Expense or Category. It asks only for the behaviour it uses. If you later add a Budget type with a Describe method, describeAll works with it unchanged.
A type satisfies an interface when its method set contains every method the interface lists, with exactly matching names, parameters and results. One missing method, or a parameter of the wrong type, and the assignment does not compile.
Pointer receivers add a wrinkle. A method with a pointer receiver is in the method set of *Expense, not of Expense. So the pointer type satisfies the interface and the value type does not.
package main
import "fmt"
type Namer interface {
Name() string
}
type Expense struct {
Description string
}
// Name has a pointer receiver, so *Expense has this method, not Expense.
func (e *Expense) Name() string {
return e.Description
}
func main() {
coffee := &Expense{Description: "Coffee"}
var namer Namer = coffee
fmt.Println("named:", namer.Name())
}Write var namer Namer = coffee where coffee is an Expense value, and the compiler says Expense does not implement Namer (method Name has pointer receiver). That message is precise: it names the missing method and the receiver problem.
fmt.Stringer: The Interface You Already UseYou have been using an interface since the first lesson without knowing it. fmt.Println accepts values of any type, and when a value has a String() string method, fmt calls it instead of printing raw fields. The interface is built into a package you already import:
type Stringer interface { String() string } - that is the whole thing, defined in the fmt package.
package main
import "fmt"
type Expense struct {
ID int
Cents int
}
// String makes Expense a fmt.Stringer.
func (e Expense) String() string {
return fmt.Sprintf("#%d: $%d.%02d", e.ID, e.Cents/100, e.Cents%100)
}
func main() {
coffee := Expense{ID: 1, Cents: 450}
fmt.Println(coffee)
fmt.Printf("with %%v: %v\n", coffee)
}This is the payoff of interfaces: you teach one function, fmt.Println, to print your type nicely by implementing a method. You never change fmt and fmt never imports your package.
Go's standard library is full of one-method interfaces: io.Writer has Write, io.Reader has Read, error has Error. Small interfaces are easy to satisfy, easy to combine, and easy to replace with a fake in a test.
Stringer, Reader and Writer describe what a value can do, not what it is.Define a Totaler interface with one method, Total() int. Make an Expense type satisfy it by returning e.Cents, then write func printTotal(totaler Totaler) that prints the number. Call it with an Expense. Last, add a second type MonthlyBudget that also satisfies Totaler, and pass both to printTotal.
Key takeaways
An interface lists behaviour: method names and signatures, no bodies.
A type satisfies an interface implicitly by having all of its methods.
Pointer-receiver methods belong to the pointer type's method set, not the value type's.
fmt.Stringer is a one-method interface that controls how fmt prints your type.
Prefer small interfaces, defined by the code that consumes them.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.