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 - Go Tutorial
From the course: Treating Go as an Object-Oriented Language
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
-
-
-
-
(Locked)
Structs as classes2m 21s
-
(Locked)
Creating a struct5m 16s
-
(Locked)
Encapsulation2m 43s
-
(Locked)
Leveraging encapsulation5m 35s
-
(Locked)
Solution: Struct as class2m 2s
-
(Locked)
Composition1m 36s
-
(Locked)
Leveraging composition4m 11s
-
(Locked)
Polymorphism2m 59s
-
(Locked)
Leveraging polymorphism4m 49s
-
(Locked)
Solution: OOP4m 56s
-
(Locked)
-