forked from go/golangs_learn
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.
41 lines
586 B
41 lines
586 B
package abstract_factory
|
|
|
|
import "fmt"
|
|
|
|
type Lunch interface {
|
|
Cook()
|
|
}
|
|
|
|
type Rise struct {
|
|
}
|
|
|
|
func (r *Rise) Cook() {
|
|
fmt.Println("这是 测试1111。")
|
|
}
|
|
|
|
type Tomato struct {
|
|
}
|
|
|
|
func (t *Tomato) Cook() {
|
|
fmt.Println("这是 测试22222。")
|
|
}
|
|
|
|
type LunchFactory interface {
|
|
CreateFood() Lunch
|
|
CreateVegetable() Lunch
|
|
}
|
|
|
|
type SimpleLunchFactory struct {
|
|
}
|
|
|
|
func NewSimpleLunchFactory() LunchFactory {
|
|
return &SimpleLunchFactory{}
|
|
}
|
|
|
|
func (s *SimpleLunchFactory) CreateFood() Lunch {
|
|
return &Rise{}
|
|
}
|
|
|
|
func (s *SimpleLunchFactory) CreateVegetable() Lunch {
|
|
return &Tomato{}
|
|
}
|
|
|