Skip to content

Instantly share code, notes, and snippets.

@Nydan
Created December 30, 2018 04:50
Show Gist options
  • Save Nydan/18390cf46fdf30fbe0fdaf8625e168bc to your computer and use it in GitHub Desktop.
Save Nydan/18390cf46fdf30fbe0fdaf8625e168bc to your computer and use it in GitHub Desktop.
Interface example
package main
// Dog struct
type Dog struct{}
// Speak is receiver method for how the dog speak
func (d *Dog) Speak() string {
return "woof"
}
// Animal interface that going to consume the type Dog implementation
type Animal interface {
Speak() string
}
func main() {
var a Animal
a = &Dog{}
fmt.Println(a.Speak())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment