You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
401 B

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
}