Skip to content

Instantly share code, notes, and snippets.

@supercaracal
Created May 13, 2023 10:43
Show Gist options
  • Save supercaracal/2fb779037d0458cfa6ebc1b1e25749c7 to your computer and use it in GitHub Desktop.
Save supercaracal/2fb779037d0458cfa6ebc1b1e25749c7 to your computer and use it in GitHub Desktop.
How to call child methods from parent methods
package main
import "fmt"
type parent struct {
b func() string
}
func (p *parent) a() string {
if p.b == nil {
return "not implemented yet: #b"
}
return p.b()
}
type child struct {
parent
}
func (c *child) b() string {
return "child"
}
func main() {
c := &child{}
c.parent.b = c.b
fmt.Println(c.a())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment