Last active
June 27, 2017 08:36
-
-
Save i-van/f737c3cb74c58fa26514ab15d0219fe9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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