package Simple_Factory import "fmt" //创造型模式 //1.Simple Factory 简单工厂 type People interface { Say(name string) } type Student struct {} func(*Student) Say(name string) { fmt.Printf("I am %s \n",name) } type Teacher struct {} func (*Teacher)Say(name string){ fmt.Printf("I am %s \n",name) } func NewPeople(s string) People { if s == "student"{ return &Student{} } if s == "teacher"{ return &Teacher{} } return nil }