Contemplate this instance:
package deal primary
import (
"fmt"
)
kind A struct {}
func (a *A) TheMethod() {
fmt.Println("TheMethod (A's implementation)")
}
kind B struct {
A
}
func (b *B) TheMethod() {
fmt.Println("TheMethod (B's implementation)")
}
func (a *A) TheMethodCallingTheMethod() {
a.TheMethod()
}
func primary() {
foo := B{}
foo.TheMethodCallingTheMethod()
}
The output is TheMethod (A's implementation)
which is sort-of comprehensible.
Nevertheless, shouldn’t it ideally be TheMethod (B's implementation)
?
The rationale is that B already can transparently see A’s strategies. So, why would A’s TheMethodCallingTheMethod
(when known as from an occasion of B) not be capable to transparently see that it’s B calling it, not A, and therefore, name B’s TheMethod
not A’s?