-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfacade.go
66 lines (51 loc) · 1.23 KB
/
facade.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
66
/*!
* \brief Facade. Provide a unified interface to a set of
* interfaces in a subsystem. Facade defines a higher-level
* interface that makes the subsystem easier to use.
*/
package main
import "fmt"
type LetterProcessor interface {
WriteContext(contex string)
FillEnvelope(address string)
SendLetter()
}
type Letter struct {
contex string
address string
}
func CreateLetter() *Letter {
return &Letter{}
}
func (le *Letter) WriteContext(contex string) {
le.contex = contex
}
func (le *Letter) FillEnvelope(address string) {
le.address = address
}
func (le *Letter) CheckLetter() {
fmt.Printf("CheckLetter -> Address: %s. Context: %s.\n", string(le.address), string(le.contex))
}
//////
type Sender interface {
SendLetter(contex string, address string)
}
type PostOfficer struct {
letter *Letter
}
func CreatePostOfficer() *PostOfficer {
return &PostOfficer{
letter: CreateLetter(),
}
}
func (po *PostOfficer) SendLetter(contex string, address string) {
po.letter.WriteContext(contex)
po.letter.FillEnvelope(address)
po.letter.CheckLetter()
}
//////
func main() {
officer := CreatePostOfficer()
officer.SendLetter("Nice to meet you", "Guangzhou")
officer.SendLetter("nice to meet you too", "Beijing")
}