-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathContents.swift
54 lines (42 loc) · 891 Bytes
/
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
//: Playground - noun: a place where people can play
// Powered by https://maimieng.com from https://github.com/kingcos/Swift-X-Design-Patterns
import UIKit
// 手机软件协议
protocol HandsetSoft {
func run()
}
// 手机游戏
struct HandsetGame: HandsetSoft {
func run() {
print("Run GAME")
}
}
// 手机通讯录
struct HandsetAddressList: HandsetSoft {
func run() {
print("Run ADDRESS LIST")
}
}
// 手机品牌协议
protocol HandsetBrand {
var soft: HandsetSoft { get }
func run()
}
// 品牌 A
struct HandsetBrandA: HandsetBrand {
var soft: HandsetSoft
func run() {
soft.run()
}
}
// 品牌 B
struct HandsetBrandB: HandsetBrand {
var soft: HandsetSoft
func run() {
soft.run()
}
}
var hs = HandsetBrandA(soft: HandsetGame())
hs.run()
hs.soft = HandsetAddressList()
hs.run()