I think this is the right way, but I just wanted to verify since every video and article I find seems to show DI or Polymorphism but not both.
Does the following code do both in the most idiomatic Golang way?
package aminolllls
type Pet interface {
Speak()
}
func (d *Dog) Speak() {
// bark
}
func (c *Cat) Speak() {
// meow
}
type Dog struct {
someOtherInterface
}
type Cat struct {
someOtherInterface
}
func NewDogType(foo someOtherInterface) Dog{
return Dog{foo}
}
func NewCatType(foo someOtherInterface) Cat{
return Cat{foo}
}