Skip to content

Instantly share code, notes, and snippets.

@yassu
Created June 12, 2016 08:37
Show Gist options
  • Save yassu/f87079a73974a39bfc519db204f70e5c to your computer and use it in GitHub Desktop.
Save yassu/f87079a73974a39bfc519db204f70e5c to your computer and use it in GitHub Desktop.
sample of interface for golang
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