title: Golang Inheritance and method override
body: <p>Clarification: I'm just learning GO, and came across this problem.</p>
  
  <p>I'm trying to implement a "class" that inherit a method that invokes a "virtual" method that should be implemented by the child class. Here's my code:</p>
  
  <p><a href="https://play.golang.org/p/ysiaPwARkvl" rel="nofollow noreferrer">https://play.golang.org/p/ysiaPwARkvl</a></p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "sync"
  )
  
  type Parent struct {
    sync.Mutex
    MyInterface
  }
  
  func (p *Parent) Foo() {
    p.Lock()
    defer p.Unlock()
    p.Bar()
  }
  
  func (p *Parent) B(){
    panic("NOT IMPLEMENTED")
  }
  
  func (p *Parent) A() {
    p.Lock()
    defer p.Unlock()
    p.B()
  }
  
  type MyInterface interface {
    Foo()
    Bar()
  }
  
  type Child struct {
    Parent
    Name string
  }
  
  func (c *Child) Bar(){
    fmt.Println(c.Name)
  }
  
  func (c *Child) B(){
    fmt.Println(c.Name)
  }
  
  func main() {
    c := new(Child)
    c.Name = "Child"
    // c.A() panic
    c.Foo() // pointer error
  }
  </code></pre>
  
  <p>I left out some code regarding the sync.Mutex that does some async update to the values of Child. </p>
  
  <p>So apparently in A() or Foo() the pointer p have type Parent. How should I change my code so that A/Foo refer to B/Bar defined in the Child class?</p>