From the course: Treating Go as an Object-Oriented Language

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Polymorphism

Polymorphism

- [Narrator] Polymorphism is the last pillar we will discuss and possibly one of the ones that I use the most. And I will share with you in a bit why. So polymorphism as a whole in object-oriented programming is a very powerful construct. It gives you the ability to change behavior based on type and not the code itself. This provides a common pathway for various types that are similar to have their functionality executed without the calling method have to know what type is what and how to behave differently based on that type. It is very useful when providing these repeatable methods across a number of structs. Now, polymorphism in Go is achieved primarily through interfaces and Go Interfaces are unique in the way that they work. So Go does provide for the concept of an interface. In fact, it's nothing more than a type. It is a type of interface that is a collection of method signatures. So it's not a collection of…

Contents