| 123456789101112131415161718192021222324252627282930313233343536 |
- package Factory_Method
- import "fmt"
- //工厂方法
- type AbstractProduct interface {
- Introduce(name string)
- }
- type AbstractFactory interface {
- Create()AbstractProduct
- }
- type ProductOne struct {
- Name string
- }
- func (*ProductOne)Introduce(name string){
- fmt.Printf("This is %s \n",name)
- }
- type ProductTwo struct {
- Name string
- }
- func (*ProductTwo)Introduce(name string){
- fmt.Printf("This is %s \n",name)
- }
- type FactoryOne struct {}
- func (*FactoryOne)Create()AbstractProduct{
- return &ProductOne{}
- }
- type FactoryTwo struct {}
- func (*FactoryTwo)Create()AbstractProduct{
- return &ProductTwo{}
- }
|