Goworkinggo1

Interfaces and methods

An interface is a set of method signatures; any type with those methods satisfies it — no implements keyword.

Go interfaces are satisfied implicitly: define Area() float64 on a type and it *is* a Shape, enabling polymorphism, fmt.Stringer, and switch v := x.(type) dispatch.

A Shape interface two types satisfy

Gointro
0ms
circle area: 12.57rectangle area: 12.00
Reference · output compiled offline, not runnable in-browser

The same Shape variable s first holds a Circle then a Rectangle, and each s.Area() call dispatches to that concrete type's method — neither type ever declares it implements Shape. Implicit satisfaction is what makes this polymorphism work.