~/Object Oriented Programming in Golang
Apr 15, 2023
Golang does not have traditional object oriented programming features like classes and inheritance. Instead, it uses structs and interfaces to achieve similar results.
Structs are used to define composite types:
Interfaces specify what methods a type must have:
You can then use these to implement a form of polymorphism:
There is no inheritance. Instead, Golang uses composition via embedding:
To summarize, use structs, interfaces, and embedding for OOP in Go.