Interfaces

Let’s learn about interfaces and how they work in Go.

What is an interface?

An interface is a Go mechanism for defining behavior that is implemented using a set of methods. Interfaces play a key role in Go and can simplify the code of our programs when they have to deal with multiple data types that perform the same task—recall that fmt.Println() works for almost all data types. But remember, interfaces should not be unnecessarily complex. If we decide to create our own interfaces, then we should begin with a common behavior that we want to be used by multiple data types.

Get hands-on with 1400+ tech skills courses.