mohanraj-r
3/7/2017 - 6:44 PM

Duck typing using interface

Duck typing using interface

// Duck typing using interface

package main

import "fmt"

type Quacker interface {
	Quack()
}

type Duck struct {
}

func (d Duck) Quack() {
	fmt.Println("Duck says Quack!")
}

type Platypus struct {
}

func (p Platypus) Quack() {
	fmt.Println("Platypus zaps izzz..")
}

type Bird struct {
	q Quacker
}

func main() {
	d := Duck{}
	b := Bird{Quacker(d)}
	b.q.Quack()
}