forked from qq570850096/awesome-golang-DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridge.go
55 lines (41 loc) · 722 Bytes
/
Bridge.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
package StructuralType
import "fmt"
type MobilePhone struct {
Impl SoftImplementor
}
func (MobilePhone) Run() {}
type SoftImplementor interface {
RawRun()
}
type GameSoft struct {
SoftImplementor
}
type ChatSoft struct {
SoftImplementor
}
func (GameSoft)RawRun() {
fmt.Println("游戏软件启动")
}
func (ChatSoft)RawRun() {
fmt.Println("聊天软件启动")
}
type HuaWei struct {
MobilePhone
}
func (h *HuaWei) Run() {
h.Impl.RawRun()
}
func (h *HuaWei) GPUTurbo() {
fmt.Println("GPUTurbo started")
h.Run()
fmt.Println("GPUTurbo ended")
}
type XiaoMi struct {
MobilePhone
}
func (x *XiaoMi) Run() {
x.Impl.RawRun()
}
func (x *XiaoMi) GameTurbo() {
fmt.Println("GameTurbo started.")
}