课程: Treating Go as an Object-Oriented Language

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

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…

内容