Created
May 25, 2020 13:47
-
-
Save donvito/4526004d71f3a4d394684e2f6d22afbe to your computer and use it in GitHub Desktop.
interfaces
This file contains 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
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