package factory import ( "fmt" ) type Restaurant interface { GetFood() } type Aa struct { } type Bb struct { } func (a *Aa) GetFood() { fmt.Println("Aa ... 测试工厂生产, ", &a) } func (b *Bb) GetFood() { fmt.Println("Bb ... 测试工厂生产, ", &b) } func NewRestaurant(name string) Restaurant { switch name { case "Aa": return &Aa{} case "Bb": return &Bb{} } return nil }