Created
June 12, 2016 08:37
-
-
Save yassu/f87079a73974a39bfc519db204f70e5c to your computer and use it in GitHub Desktop.
sample of interface for golang
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
package main | |
import ( | |
"fmt" | |
) | |
type Animal interface { | |
Cow() string | |
} | |
type Horse struct{} | |
func (_ Horse) Cow() string { | |
return "xyz" | |
} | |
type Turtle struct{} | |
func (_ Turtle) Cow() string { | |
return "Doo" | |
} | |
func PrintCow(a Animal) { | |
fmt.Println(a.Cow()) | |
} | |
func main() { | |
animal := new(Turtle) | |
PrintCow(animal) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment