-
Notifications
You must be signed in to change notification settings - Fork 12
/
builder.cr
52 lines (41 loc) · 1.14 KB
/
builder.cr
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
# Separates object construction from its representation.
# Separate the construction of a complex object from its representation
# so that the same construction processes can create different representations.
class StageBuilder
getter stage
def initialize(name, width, height)
@stage = Stage.new(name)
@stage.width = width
@stage.height = height
@stage.brutalities = [] of Brutality
end
def set_background(background)
@stage.background = background
end
def add_brutality(brutality)
@stage.add_brutality brutality
end
end
class Stage
getter name : String
property width, height
property background : Background?
property brutalities = [] of Brutality
def initialize(@name, @width = 800, @height = 600)
end
def add_brutality(brutality : Brutality)
brutalities << brutality
end
end
class Brutality; end
class Background; end
builder = StageBuilder.new("Dead Pool", 800, 600)
builder.set_background(Background.new)
builder.add_brutality(Brutality.new)
builder.add_brutality(Brutality.new)
stage = builder.stage
puts stage.name, stage.width, stage.height, stage.brutalities.size
# Dead Pool
# 800
# 600
# 2