luoheng
9/22/2019 - 3:28 AM

策略模式

实现共同的接口,由同一个对象进行调用

package design

// Strategy represent strategy pattern
type Strategy interface {
	shout()
}

type dog int
type chicken int
type bird int

func (d dog) shout() {
	println("wang wang...")
}

func (c chicken) shout() {
	println("luo luo...")
}

func (b bird) shout() {
	println("jo jo...")
}

// Context contains all strategies
func Context(s Strategy) {
	s.shout()
}