I am a golang newbie so pardon me if there is something obvious I am missing. I have the following structures:
type base interface {
func1()
func2()
common_func()
}
type derived1 struct {
base // anonymous meaning inheritence
data DatumType
}
type derived2 struct {
base // anonymous meaning inheritence
data DatumType
}
Now I want to do the following:
- Keep '
data DatumType
' withbase
in some way so that looking at the definition ofbase
one can know what data is common to all structs.- Implement
common_func()
in one place so that the derived structs don't need to do it.
- Implement
I tried implementing the function with the interface but it fails compilation. I tried to create a struct and inherit from that but am not finding good ways to do that. Is there some clean way out ?