Interfaces should be small, composable, and boring. The goal is to make dependencies easy to stub and to keep public APIs steady.
The one-method rule
Most of my interfaces expose a single method. If I need more, I usually create a second interface and embed it when needed.
// Small surface, easy to fake.
type Store interface {
Get(ctx context.Context, id string) (Item, error)
}
Direction over size
- Put the interface in the package that consumes it.
- Keep implementations private when possible.
- Prefer function types for tiny behaviors.