-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.ts
57 lines (49 loc) · 1.06 KB
/
builder.ts
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
class Car { }
class Manual { }
abstract class Builder {
reset() { }
setWheels() { }
setColor() { }
}
class CarBuilder extends Builder {
private car!: Car;
reset() {
this.car = new Car()
}
setColor() { }
setWheels() { }
getResult(): Car {
return this.car;
}
}
class ManualBuilder extends Builder {
private manual!: Manual;
reset() {
this.manual = new Manual()
}
setColor() { }
setWheels() { }
getResult(): Manual {
return this.manual;
}
}
class Director {
private builder: Builder;
constructor(builder: Builder) {
this.builder = builder;
}
createCar() {
this.builder.setColor();
this.builder.setWheels();
}
createManual(builder: Builder) {
builder.setWheels();
builder.setColor();
}
}
let builderCar = new CarBuilder();
let builderManual = new ManualBuilder();
let director = new Director(builderCar);
director.createManual(builderManual);
let car = builderCar.getResult();
let manual = builderManual.getResult();