This is a creation in Article, where the information may have evolved or changed. The type definition of the Go language is very close to the structure in C (struct), and even the struct keyword is directly inherited. In contrast, the go language does not directly follow the tradition of C + + and Java to design a super complex type system that does not support inheritance and overloading, but only supports the most basic types of combination functionality.
Cleverly, while seemingly supporting features that are too concise to use, you will find that the features of C + + and Java using complex type systems do not appear to be impossible to perform in the go language, but rather as a reflection of the need to introduce these complex concepts into other languages. We will describe in detail the type system of the go language in the 3rd chapter.
The go language is not simply a subtraction of the object-oriented development language, it also introduces an incredibly powerful "non-intrusive" interface concept that frees developers from previous interface management issues in C + + and Java development. In C + +, we typically do this to determine the relationship between an interface and a type:
Abstract interface Interface ifly{virtual void Fly () =0;};/ /Implement Class Bird:public Ifly{public:bird () {}virtual ~bird () {}public:void fly () {//Fly in a bird}};void main () {ifly* pfly = new Bird ();p fly->fly ();d elete Pfly;}
obviously, before implementing an interface, you must define the interface and tightly bind the type and interface, that is, the modification of the interface affects all the types that implement the interface, and the interface architecture of the go language avoids such problems:
Type Bird struct {...} Func (b *bird) Fly () {//Fly in Bird's Way} diagram
We do not have any ifly information when implementing the bird type. We can define this ifly interface in another place:
Type IFly Interface {Fly ()}
the two don't seem to matter at all now, so let's see how we can use them:
Func main () {var fly IFly = new (Bird) fly. Fly ()}
As you can see, although the bird type is implemented without declaring a relationship with the interface ifly, the interface and type can be converted directly, and even if the interface definition is not used before the type definition, this loosely-coupled correspondence can significantly reduce the amount of code-tuning work that results from an interface adjustment.