I have the following:
type Base struct {
}
func(base *Base) Get() string {
return "base"
}
func(base *Base) GetName() string {
return base.Get()
}
I want to define a new type with a new implementation of Get() so that I can use the new type in place of Base
and where GetName() is called it calls the new Get() implementation . If I were using Java I would inherit Base and override Get(). How should I achieve this in Go? I want to avoid breaking changes if possible, so existing consumers of Base do not need to be changed.
My first stab at this looks like..
type Sub struct {
Base
}
func(sub *Sub) Get() string {
return "Sub"
}
..which doesn't work. My brain isn't wired for Go yet clearly.