golang struct embedding
In golang it doesn't quite has inheritance, instead it uses embedding. For example, let's take a look at the following
Here we are looking at embedding where C would be able to call Foo() directly or via c.A.Foo()
package main
type A struct{}
func (A) Foo() {}
type B struct{ A }
type C struct{ A }
func main() {
c := C{}
c.Foo()
c.A.Foo()
}
Comments