-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfacede.go
More file actions
68 lines (53 loc) · 921 Bytes
/
facede.go
File metadata and controls
68 lines (53 loc) · 921 Bytes
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
66
67
68
package ch12
import "fmt"
// 外观模式
type SubSystem1 struct {
}
func (s *SubSystem1) Method1() {
fmt.Println("SubSystem1 Method1")
}
type SubSystem2 struct {
}
func (s *SubSystem2) Method2() {
fmt.Println("SubSystem2 Method2")
}
type SubSystem3 struct {
}
func (s *SubSystem3) Method3() {
fmt.Println("SubSystem3 Method3")
}
type SubSystem4 struct {
}
func (s *SubSystem4) Method4() {
fmt.Println("SubSystem4 Method4")
}
type Facade struct {
s1 *SubSystem1
s2 *SubSystem2
s3 *SubSystem3
s4 *SubSystem4
}
func NewFacade() *Facade {
return &Facade{
s1: &SubSystem1{},
s2: &SubSystem2{},
s3: &SubSystem3{},
s4: &SubSystem4{},
}
}
func (f *Facade) MethodA() {
fmt.Println("MethodA")
f.s1.Method1()
f.s2.Method2()
f.s4.Method4()
}
func (f *Facade) MethodB() {
fmt.Println("MethodB")
f.s3.Method3()
f.s4.Method4()
}
func FacadeTest() {
f := NewFacade()
f.MethodA()
f.MethodB()
}