Skip to content

Instantly share code, notes, and snippets.

@jcelliott
Last active December 22, 2015 14:48
Show Gist options
  • Save jcelliott/6487850 to your computer and use it in GitHub Desktop.
Save jcelliott/6487850 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Quacker interface {
Quack()
}
type Duck struct{}
func (d Duck) Quack() {
fmt.Println("duck: quack quack")
}
type Cat struct{}
func (c Cat) Quack() {
fmt.Println("cat: quack quack")
}
func main() {
var q Quacker = new(Duck)
q.Quack()
q = new(Cat) // a cat *is* a Quacker
q.Quack()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment