Polymorphism in Go - without interfaces 🦆
Ok, so you want to use polymorphism in Go, but don’t like interfaces? Read on… First, let’s see what we want to do: var dog, duck *Animal dog = NewDog("fido") duck = NewDuck("donald") fmt.Println(dog.makeNoise()) // fido says woof! fmt.Println(duck.makeNoise()) // donald says quack! Here, dog and duck are of the same type (*Animal). Each variable is instantiated with a different constructor, and they have different behaviours when the same method makeNoise is called....