-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContents.swift
60 lines (47 loc) · 1.16 KB
/
Contents.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
import Security
protocol Coworker {
func hire(coworker: Coworker)
func getInfo()
var level: Int { get }
}
//MARK: - Branch
class Manager: Coworker {
private var coworkers = [Coworker]()
var level: Int
init(level: Int) {
self.level = level
}
func hire(coworker: Coworker) {
self.coworkers.append(coworker)
}
func getInfo() {
print(self.level.description + " level manager")
for coworker in coworkers {
coworker.getInfo()
}
}
}
//MARK: - Leaf
class LowLevelManager: Coworker {
var level: Int
init(level: Int) {
self.level = level
}
func hire(coworker: Coworker) {
print("can't hire")
}
func getInfo() {
print(self.level.description + " level manager")
}
}
//MARK: - Tests
let managerLvl1 = Manager(level: 1)
let managerLvl2 = Manager(level: 2)
let managerLvl3_1 = Manager(level: 3)
let managerLvl3_2 = Manager(level: 3)
let managetLvl5 = Manager(level: 5)
managerLvl1.hire(coworker: managerLvl2)
managerLvl2.hire(coworker: managerLvl3_1)
managerLvl2.hire(coworker: managerLvl3_2)
managerLvl3_1.hire(coworker: managetLvl5)
managerLvl1.getInfo()