Home > Backend Development > Golang > What is the difference between composition and inheritance in golang?

What is the difference between composition and inheritance in golang?

青灯夜游
Release: 2020-04-17 13:35:02
Original
4949 people have browsed it

The Go language (golang) is a general-purpose programming language designed by Google; it borrows many good ideas from many other languages ​​while avoiding features that lead to complexity and unreliable code.

What is the difference between composition and inheritance in golang?

Go supports multiple paradigms such as procedural, functional and concurrency. Its syntax is traditionally derived from the C language, but it has been significantly modified to improve features such as simplicity and safety.

The difference between golang combination and inheritance

Inheritance in GO language is also realized through combination. The specific difference between the two is as follows:

If If a struct nests another named structure, this pattern is called composition.

If a struct nests another anonymous structure (only the type without a name), then this structure can directly access the methods of the anonymous structure, thus realizing inheritance.

If a struct nests multiple anonymous structures, then this structure can directly access the methods of multiple anonymous structures, thus achieving multiple inheritance.

Recommended learning: Golang tutorial

The above is the detailed content of What is the difference between composition and inheritance in golang?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template