Skip to content

Instantly share code, notes, and snippets.

@i-van
Last active June 27, 2017 08:36
Show Gist options
  • Save i-van/f737c3cb74c58fa26514ab15d0219fe9 to your computer and use it in GitHub Desktop.
Save i-van/f737c3cb74c58fa26514ab15d0219fe9 to your computer and use it in GitHub Desktop.
type Animal interface {
Speak() string
}
type Dog struct {
}
func (d Dog) Speak() string {
return "Woof!"
}
type Cat struct {
}
func (c Cat) Speak() string {
return "Meow!"
}
type Llama struct {
}
func (l Llama) Speak() string {
return "?????"
}
type JavaProgrammer struct {
}
func (j JavaProgrammer) Speak() string {
return "Design patterns!"
}
func main() {
animals := []Animal{Dog{}, Cat{}, Llama{}, JavaProgrammer{}}
for _, animal := range animals {
fmt.Println(animal.Speak())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment