Code here
package main
import "fmt"
func main() {
t16()
}
type Base struct {
val int
}
func (b *Base)Set(i int) {
b.val = i
}
type Sub struct {
Base
changed bool
}
func (b *Sub)Set(i int) {
b.val = i
b.changed = true
}
func t16() {
s := &Sub{}
s.Base.Set(1)
var b *Base = &s.Base
fmt.Printf("%+v
", b)
fmt.Printf("%+v
", s)
}
I want to make Sub act as Base, but when I call Set, for Sub it will mark the changed.I know there is no polymorphism or proxy in golang, but is there any way to do this, and not effect the Base?
UPDATED
I hope when I call Base.Set it will mark the change, for user, they don't know they actually use the Sub, so I can monitor the Base behave.
func t16() {
s := &Sub{}
var b *Base = &s.Base
b.Set(10)
fmt.Printf("%+v
", b)
fmt.Printf("%+v
", s)
}