-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacadePattern.swift
133 lines (112 loc) · 2.51 KB
/
FacadePattern.swift
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// FacadePattern.swift
// Design-Patterns
//
// Created by liupengkun on 2020/5/9.
// Copyright © 2020 刘朋坤. All rights reserved.
//
/*
外观模式(Facade Pattern):外观模式定义了一个高层接口,为子系统中的一组接口提供一个统一的接口。外观模式又称为门面模式,它是一种结构型设计模式模式。
*/
import UIKit
class FacadePattern: NSObject {
let xcode = Xcode.init()
let vscode = VSCode.init()
let charles = Charles.init()
let sourceTree = SourceTree.init()
// 打开所有软件
func allON() {
let tools = [xcode, vscode, charles, sourceTree]
tools.forEach { (tool) in
tool.on()
}
}
// 关闭所有软件
func allOFF() {
let tools = [xcode, vscode, charles, sourceTree]
tools.forEach { (tool) in
tool.off()
}
}
// 写OC代码
func codingOC() {
xcode.on()
xcode.codingOC()
}
// 写Swift代码
func codingSwift() {
xcode.on()
xcode.codingSwift()
}
// 写Flutter代码
func codingFlutter() {
vscode.on()
vscode.codingFlutter()
}
// 写JS代码
func codingJS() {
vscode.on()
vscode.codingJS()
}
// 抓包真机
func captureMobilePhone() {
charles.on()
charles.captureMobilePhone()
}
// 抓包模拟器
func captureSimulator() {
charles.on()
charles.captureMobilePhone()
}
// 创建新分支
func gitCheckOut() {
sourceTree.on()
sourceTree.gitCheckOut()
}
// 提交代码
func gitPush() {
sourceTree.on()
sourceTree.gitPush()
}
}
// 工具父类
class SoftwareTools: NSObject {
func on() {
print(self, "已打开")
}
func off() {
print(self, "已关闭")
}
}
class Xcode: SoftwareTools {
func codingOC() {
print("写OC")
}
func codingSwift() {
print("写Swift")
}
}
class VSCode: SoftwareTools {
func codingFlutter() {
print("写Flutter")
}
func codingJS() {
print("写JS")
}
}
class Charles: SoftwareTools {
func captureMobilePhone() {
print("抓包真机")
}
func captureSimulator() {
print("抓包模拟器")
}
}
class SourceTree: SoftwareTools {
func gitCheckOut() {
print("创建新分支")
}
func gitPush() {
print("提交代码")
}
}