I'm coming from a language like C++ where OOP is well defined and polymorphism is commonly used. I'm new using Go and I'm trying to call child method from a polymorphism and I have no idea what's is the right pattern.
I created two structs as u'll see, and I defined 2 methods fun1 and fun2 where in the base struct i override only one of them, and in the parent i'm calling it. If the polymorphism is correct, this child method should be called and at least in my example, this is not happenning
Here is the code:
package main
import (
"fmt"
)
type A struct {
}
type B struct {
A
}
func (a* A) fun1() {
fmt.Println("I'm in A.fun1()")
a.fun2()
}
func (a* A) fun2() {
fmt.Println("I'm in A.fun2()")
}
func (b* B) fun2() {
fmt.Println("I'm in B.fun2()")
}
func main() {
b := B{}
b.fun1()
}
You can try it here: https://play.golang.org/p/s7xZun-6Otx
The output was
I'm in A.fun1()
I'm in A.fun2()
and I wasexpected
I'm in A.fun1()
I'm in B.fun2()
How can I do that? what's the right way for having a good design in Go for this?
Regards