design model 之 subcribe/publish 发表于 2018-08-10 | 分类于 设计模式 简单工厂模式1234567891011121314151617181920212223242526272829303132type sayer interface { say()}type man struct{}func (m *man)say(){ fmt.Printf("I am man")}type woman struct{}func (w *woman)say(){ fmt.Printf("I am woman")}func factory(t string) sayer{ if t=="man" { return &man{} }else{ return &woman{} }}func main(){ s := factory("man") s.say()}