100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Go

Interfaces in Go

Learn how Go interfaces define behavior through implicit, structural typing without classes or inheritance.

Interfaces & CompositionIntermediate9 min readJul 8, 2026
Analogies

Introduction

An interface in Go is a type that specifies a set of method signatures. Unlike languages such as Java or C#, Go interfaces are satisfied implicitly: a concrete type does not declare that it implements an interface. If a type has all the methods an interface requires, it automatically satisfies that interface. This structural typing keeps packages decoupled, since the type that implements an interface never needs to know the interface exists.

🏏

Cricket analogy: Go's implicit interface satisfaction is like a player who never formally registers as an "all-rounder" but is automatically treated as one by selectors simply because they can both bat and bowl to the required standard.

Syntax

go
type Shape interface {
    Area() float64
    Perimeter() float64
}

type Rectangle struct {
    Width, Height float64
}

func (r Rectangle) Area() float64 {
    return r.Width * r.Height
}

func (r Rectangle) Perimeter() float64 {
    return 2 * (r.Width + r.Height)
}

Explanation

The Shape interface declares two methods, Area and Perimeter. Rectangle never mentions Shape anywhere in its declaration, yet because it defines both methods with matching signatures, a Rectangle value can be used anywhere a Shape is expected. This is the essence of structural typing. Go also has an empty interface, written as interface{} or the alias any, which has zero methods and is therefore satisfied by every type, making it useful for holding values of unknown type.

🏏

Cricket analogy: Rectangle satisfying Shape without mentioning it is like a bowler who's never labeled a "death-over specialist" by the team sheet, yet gets used in that role in every match simply because their skill set matches, just as any Shape is expected to.

Example

go
package main

import "fmt"

type Shape interface {
    Area() float64
}

type Circle struct {
    Radius float64
}

func (c Circle) Area() float64 {
    return 3.14159 * c.Radius * c.Radius
}

func describe(s Shape) {
    fmt.Printf("Area: %.2f\n", s.Area())
}

func main() {
    c := Circle{Radius: 4}
    describe(c)
}

Output

go
Area: 50.27

Key Takeaways

  • Interfaces are satisfied implicitly; there is no 'implements' keyword in Go.
  • A type satisfies an interface simply by defining all its required methods.
  • The empty interface (interface{} or any) can hold a value of any type.
  • Interfaces enable polymorphism and decoupling without inheritance.

Practice what you learned

Was this page helpful?

Topics covered

#Go#GoProgrammingStudyNotes#Programming#InterfacesInGo#Interfaces#Syntax#Explanation#Example#StudyNotes#SkillVeris