Created
October 2, 2021 20:22
-
-
Save mkock/b419d1f75b212c85f53bb0385ef6aa15 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 persona interface { | |
| strength() int | |
| intelligence() int | |
| stamina() int | |
| } | |
| type dwarf struct {} | |
| func (d *dwarf) strength() int { return 80 } | |
| func (d *dwarf) intelligence() int { return 55 } | |
| func (d *dwarf) stamina() int { return 90 } | |
| type wizard struct {} | |
| func (w *wizard) strength() int { return 50 } | |
| func (w *wizard) intelligence() int { return 90 } | |
| func (w *wizard) stamina() int { return 60 } | |
| type player struct { | |
| persona | |
| } | |
| func main() { | |
| p := player{&wizard{}} | |
| fmt.Println(p.intelligence()) // Prints 90. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment