I've been trying to build a set of structs that have a base struct as their foundation and variants built on top of that. I've found, however, that there doesn't seem to be a way for the struct to identify itself when the common code is in the base struct. How should I be doing this?
package main
import (
"fmt"
)
type Base interface {
IsMe(other Base) bool
}
type Block struct {
}
func (b *Block) IsMe(other Base) bool {
return b == other
}
type Block2 struct {
Block
}
func main() {
b1 := &Block{}
b2 := &Block2{}
fmt.Printf("b1.IsMe(b1): %v
", b1.IsMe(b1))
fmt.Printf("b1.IsMe(b2): %v
", b1.IsMe(b2))
fmt.Printf("b2.IsMe(b1): %v
", b2.IsMe(b1)) // Wrong result!
fmt.Printf("b2.IsMe(b2): %v
", b2.IsMe(b2)) // Wrong result!
}