Inheritance in Go
Why doesn't Go support traditional type inheritance?
Traditional type inheritance, where a subclass inherits the definitions of one or more parent classes, is not a feature of the Go programming language.
Creators' Rationale
In the Go FAQ, the language creators explain that object-oriented programming languages often emphasize defining relationships between types, which can be automatically inferred in Go. Instead of explicitly specifying type relationships, Go types automatically satisfy any interface that specifies a subset of their methods.
Benefits of Go's Approach
This approach provides several advantages:
Alternative Principle
Go promotes the principle of composition over inheritance. This involves creating new types by composing existing types, rather than using inheritance to create a new type with all the features of its parent types.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3