Why doesn't Go have Type Inheritance.
(The concept that when a class of an objects is defined, any subclass that is defined can inherit the definitions of one or more general classes)
Why doesn't Go have Type Inheritance.
(The concept that when a class of an objects is defined, any subclass that is defined can inherit the definitions of one or more general classes)
This was answered by the language creators in the F.A.Q.:
Object-oriented programming, at least in the best-known languages, involves too much discussion of the relationships between types, relationships that often could be derived automatically. Go takes a different approach.
Rather than requiring the programmer to declare ahead of time that two types are related, in Go a type automatically satisfies any interface that specifies a subset of its methods. Besides reducing the bookkeeping, this approach has real advantages. Types can satisfy many interfaces at once, without the complexities of traditional multiple inheritance. Interfaces can be very lightweight—an interface with one or even zero methods can express a useful concept. Interfaces can be added after the fact if a new idea comes along or for testing—without annotating the original types. Because there are no explicit relationships between types and interfaces, there is no type hierarchy to manage or discuss.
See also: Composition over inheritance principle.