I'm trying to reach this way of polymorphism in GO
type Discoverer interface {
Discover() string
}
type A struct {
}
func (obj A) GetTest() string {
return "im in A"
}
type B struct {
A
}
func (obj B) GetTest() string {
return "im in B"
}
func (obj A) Discover() string {
return obj.GetTest()
}
func main() {
a := A{}
b := B{}
fmt.Println(a.Discover())
fmt.Println(b.Discover())
}
Now I'm getting in output
im in A
im in A
So, my question is: It is possible to see in output
im in A
im in B
Without "override" Discover of B?
func (obj B) Discover() string {
return obj.GetTest()
}
Why? I've alot of small methods in struct (as classes) and Discover pretty the same for all structs, so I want to avoid copy&paste Discover in each struct(class)
go playground https://play.golang.org/p/nYc2hc3UbG
Thanks in advance!