EDIT++:
How to not to repeat my code in Go?
type Animal interface {
Kingdom() string
Phylum() string
Family() string
}
type Wolf struct {}
type Tiger struct {}
func (w Wolf) Kingdom() string {return "Animalia"}
func (w Wolf) Phylum() string {return "Chordata"}
func (w Wolf) Family() string {return "Canidae"}
I implemented a three methods for Wolf
type and I need to implement all the methods for Tiger
type to implement the interface. But Kingdom
and Phylum
methods are the same for both types. Is it somehow possible to implement only Family
method for Tiger
type:
func (t Tiger) Family() string {return "Felidae"}
and not to repeat all the three methods for each type?
Disclaimer
Please don't be confused with simple string returns in the methods, in a real case I need different method implementations not just pre-defined values. Using this silly style I want to avoid of defiling your brains. So skip methods at all is not the way. Thanks