-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBuilder.swift
72 lines (50 loc) · 1.26 KB
/
Builder.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
//
// Created by Kenan Atmaca
// kenanatmaca.com
//
protocol Object {
var width:Double? {get set}
var height:Double? {get set}
var color:String? {get set}
}
protocol ObjectBuilder {
var object:Object {get set}
func setWidth(width:Double?)
func setHeight(height:Double?)
func setColor(color:String?)
}
class Table: Object {
var width: Double?
var height: Double?
var color: String?
}
class Builder: ObjectBuilder {
var object: Object
init(_ object:Object) {
self.object = object
}
func setWidth(width: Double?) {
object.width = width
}
func setHeight(height: Double?) {
object.height = height
}
func setColor(color: String?) {
object.color = color
}
}
class Creator {
var builder:ObjectBuilder
init(_ builder:ObjectBuilder) {
self.builder = builder
}
func build(width:Double?,height:Double?,color:String?) {
builder.setWidth(width: width)
builder.setHeight(height: height)
builder.setColor(color: color)
}
}
let builder = Builder(Table())
let creator = Creator(builder)
creator.build(width: 200, height: 200, color: nil)
creator.builder.object.width // 200