Last active
October 3, 2021 09:24
-
-
Save mkock/5050aba5d1213b2b320c2b3cfebd7a89 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 player struct { | |
| // unexported fields | |
| } | |
| func (p *player) status() string { | |
| return "Player is eating" | |
| } | |
| func (p *player) sleep() { | |
| // implementation goes here | |
| } | |
| type monster struct { | |
| // unexported fields | |
| } | |
| func (m *monster) status() string { | |
| return "Monster is sleeping" | |
| } | |
| func (m *monster) sleep() { | |
| // implementation goes here | |
| } | |
| type character interface { | |
| status() string | |
| sleep() | |
| } | |
| func getStatus(c character) string { | |
| return c.status() | |
| } | |
| func main() { | |
| cyclops := new(monster) | |
| playerOne := new(player) | |
| fmt.Println(getStatus(cyclops)) // Prints "Monster is sleeping" | |
| fmt.Println(getStatus(playerOne)) // Prints "Player is eating" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment