Assuming I got a type named State
:
type State struct {
// ... does not matter what is inside
}
along with a method defined on it:
func (s *State) prettyName() string {
return "I am a state!"
}
Currently there is no way I can alter prettyName()
's behavior. I known that Go
intentionally escapes OOP-like inheritance and methods overloading and this would probably never change, but still: what if I need prettyName()
to behave differently depending upon whatever factor? The only solution I see is:
type State struct {
_prettyName func() string
}
func (s *State) prettyName() string {
return s._prettyName()
}
Is there a better Go
-style way to achieve the same goal?