not good! I was hit by a beauty trick!

Postscript: This is the sequel to the previous article " The Biggest Secret of JavaScript ". Following the JavaScript prototype method, it introduces the object-oriented implementation of Go language. Go language is more interesting in object-oriented. The structure and method are separated. There is no inheritance, only composition. There is a kind of polymorphism that looks very similar to DuckTyping. I think when Ken Thompson and Rob Pike and others are designing the Go language, It must have been well thought out and carefully considered. 

On the official website of the Go language, I answered whether the Go language is an object-oriented language: yes or no. Although Go language has types and methods, and allows object-oriented programming, there is no type inheritance. The concept of "interface" in Go language provides a different way. We think it is easier to use and more versatile.

Go language supports the concept of subclassing (although not completely equivalent) by embedding one type in another type. In addition, the methods in Go language are more versatile than C++ and Java. Programmers can define methods on any data type, even built-in types: such as Integer, methods are not limited to structs (classes). Similarly, the absence of type inheritance makes objects in the Go language more lightweight than C++ or Java.

Guess you like

Origin blog.csdn.net/coderising/article/details/108633560