Skip to content

Instantly share code, notes, and snippets.

@mkock
Created October 2, 2021 20:22
Show Gist options
  • Select an option

  • Save mkock/b419d1f75b212c85f53bb0385ef6aa15 to your computer and use it in GitHub Desktop.

Select an option

Save mkock/b419d1f75b212c85f53bb0385ef6aa15 to your computer and use it in GitHub Desktop.
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