Abstraction for Gos
Abstraction in Go is achieved with interfaces, error values and generics. An interface is a set of method signatures that any type satisfies implicitly, with no implements keyword. Errors are ordinary values returned from functions, and generics with type parameters let one function work across many types.
Stage: Language · Part of the Go roadmap · Last reviewed 19 November 2026
What to learn in Abstraction
- Define a small interface and satisfy it implicitly with a struct
- Return and check errors, wrapping them with fmt.Errorf and %w
- Use errors.Is and errors.As to inspect wrapped errors
- Write a generic function with a type constraint
- Explain why an empty interface value can be non-nil with a nil pointer
Abstraction interview questions
Why does Go favour small interfaces?
Because types satisfy interfaces implicitly, a small interface of one or two methods, like io.Reader, is easy for many types to implement and for consumers to accept. Define interfaces where they are used, not where types are declared.
How does error wrapping work in Go?
fmt.Errorf with the %w verb wraps an error while adding context, and the original stays reachable. errors.Is checks whether any error in the chain matches a target value, and errors.As finds one of a particular type.
Where Abstraction fits in the Go roadmap
Abstraction belongs to the Language stage (beginner level), which takes about 20 hours. Go essentials.