I've noticed how hard it is to let go of the OOP style programming I've used in Java and PHP over the last 10 years or so. I'm giving golang a go (pun intended) since a few weeks, but I'm trying to feel natural around the composition over inheritance principle golang has.
How would I define a useful interface to make sure all these structs can fulfill it? I've tried to come up with a useful example that does not involve dogs, humans or weird constructs of vehicles...
package main
type Store struct {
name string
phone string
}
type HardwareStore struct{ Store }
type FoodStore struct{ Store }
type OnlineStore struct {
Store
url string
}
I think it might be because I base my thinking around their state/data and not their behaviour, I'm struggling a bit.
The obvious first choice, without an interface, would probably be this (simplified), which of course fails:
s := Store{}
h := HardwareStore{}
f := FoodStore{}
o := OnlineStore{}
stores := []Store{s, h, f, o}