-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAbstractFactory.go
92 lines (47 loc) · 968 Bytes
/
AbstractFactory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package CreativeType
import "fmt"
type Factory interface {
NewTV() Television
NewRefrigerator() Refrigerator
}
type Television interface {
DoSomething()
}
type Refrigerator interface {
DoSomething()
}
type TCLTV struct {
}
func (TCLTV) DoSomething () {
fmt.Println("TCL电视在Do Something")
}
type TCLRef struct {
}
func (TCLRef) DoSomething () {
fmt.Println("TCL空调在do something")
}
type MediaTV struct {
}
func (MediaTV)DoSomething() {
fmt.Println("美的电视在do something")
}
type MediaRef struct{}
func (MediaRef)DoSomething() {
fmt.Println("美的空调在do something")
}
type TCLFactory struct {
}
func (TCLFactory) NewTV () Television {
return TCLTV{}
}
func (TCLFactory)NewRefrigerator () Refrigerator {
return TCLRef{}
}
type MediaFactory struct {
}
func (MediaFactory) NewTV () Television {
return MediaTV{}
}
func (MediaFactory)NewRefrigerator () Refrigerator {
return MediaRef{}
}