I have a few classes that I'm importing that have some common fields.
package foo
type FooA struct {
...
SharedVal int
}
type FooB struct {
...
SharedVal int
}
type FooC struct {
...
SharedVal int
}
For various reasons, I am unable to modify the foo package. I want to have some abstraction that gives me some sort of union typing so that I can create a setter for the sharedVal field; e.g. something like this
package bar
type GenericFoo = foo.FooA | foo.FooB | foo.FooC
func (f *GenericFoo) SetSharedVal(val int) {
f.SharedVal = val
}
How do I do this? Interfaces don't work for me since they required shared methods, but the Foo classes don't have setters. It's preferrable that the solution doesn't involve importing other third-party packages since dependency management becomes complicated in my use case.