Go isn't capable of monkey patching (hooray!), but you can do dynamic function calls from an object method if you really want to. I modified (and fixed) your code just a bit to show this.
http://play.golang.org/p/2rwCW2N93-
package main
import (
"fmt"
)
type FF func(*Foo)
type Foo struct {
foofunc FF
name string
age int
}
func foo1(f *Foo) {
fmt.Println("[foo1]", f.name)
}
func foo2(f *Foo) {
fmt.Println("[foo2] My name is ", f.name , " and my age is " , f.age)
}
type BB func(*Bar)
type Bar struct {
barFuncs []BB
salary int
debt int
}
func barSalary(b *Bar) {
fmt.Println("[barSalary] My salary is " , b.salary)
}
func barDebt(b *Bar) {
fmt.Println("[barDebt] My salary is ", b.debt)
}
func main() {
fooObject := Foo{
name: "micheal",
}
fooObject.foofunc = foo1
fooObject.foofunc(&fooObject)
fooObject = Foo{
name: "lisa",
age : 22,
}
fooObject.foofunc = foo2
fooObject.foofunc(&fooObject)
barFuncList := make([]BB, 2, 2)
barFuncList[0] = barSalary
barFuncList[1] = barDebt
barObject := Bar{
salary: 45000,
debt: 200,
barFuncs: barFuncList,
}
for i := 0; i < len(barObject.barFuncs); i++ {
barObject.barFuncs[i](&barObject)
}
}