Skip to content

Instantly share code, notes, and snippets.

@donvito
Created May 25, 2020 13:47
Show Gist options
  • Save donvito/4526004d71f3a4d394684e2f6d22afbe to your computer and use it in GitHub Desktop.
Save donvito/4526004d71f3a4d394684e2f6d22afbe to your computer and use it in GitHub Desktop.
interfaces
package main
import "fmt"
type animal interface {
Run() string
}
type dog struct {
Name string
}
type cat struct {
Name string
}
func (d dog) Run() string {
return "running " + d.Name
}
func (c cat) Run() string {
return "running " + c.Name
}
func main() {
testrun(dog{Name: "Lassy"})
testrun(cat{Name: "Kitty"})
}
func testrun(a animal) {
fmt.Print(a.Run())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment