Composition vs Inheritance

This explains details of Composition in Go and how it can be used as an alternative to Inheritance in Go.

Composition as an Alternative to Inheritance

Coming from an OOP background a lot of us are used to inheritance, something that isn’t supported by Go. Instead you have to think in terms of composition and interfaces. In the previous lessons, we learnt about structs in Go, and that is what we will be using for composition.

The Go team wrote a short but good segment on this topic.


Composition (or embedding) is a well understood concept for most OOP programmers and Go supports it, here is an example of the problem it’s solving:

Get hands-on with 1200+ tech skills courses.