-
Notifications
You must be signed in to change notification settings - Fork 5
/
builder.go
68 lines (53 loc) · 1.12 KB
/
builder.go
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
package builder
type Product struct {
Wheels int
Seats int
}
type VehicleBuildProcess interface {
SetWheelsNumber() VehicleBuildProcess
SetSeatsNumber() VehicleBuildProcess
GetVehicle() Product
}
type ManufacturingDirector struct {
builder VehicleBuildProcess
}
func (f *ManufacturingDirector) SetBuilder(b VehicleBuildProcess) {
f.builder = b
}
func (f *ManufacturingDirector) Construct() {
f.builder.SetSeatsNumber().SetWheelsNumber()
}
type CarBuilder struct {
p Product
}
func (c *CarBuilder) SetWheelsNumber() VehicleBuildProcess {
c.p.Seats = 5
return c
}
func (c *CarBuilder) SetSeatsNumber() VehicleBuildProcess {
c.p.Wheels = 4
return c
}
func (c *CarBuilder) GetVehicle() Product {
return c.p
}
func (c *CarBuilder) Build() Product {
return c.p
}
type BiciclettaBuilder struct {
p Product
}
func (c *BiciclettaBuilder) SetWheelsNumber() VehicleBuildProcess {
c.p.Seats = 1
return c
}
func (c *BiciclettaBuilder) SetSeatsNumber() VehicleBuildProcess {
c.p.Wheels = 2
return c
}
func (c *BiciclettaBuilder) GetVehicle() Product {
return c.p
}
func (c *BiciclettaBuilder) Build() Product {
return c.p
}