-
Notifications
You must be signed in to change notification settings - Fork 74
/
Builder.js
54 lines (46 loc) · 1.19 KB
/
Builder.js
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
'use strict';
class Builder {
constructor() {
console.log('Builder Class created!');
}
buildPart(partName) {
console.log('Builder.buildPart invoked!');
}
}
class ConcreteBuilder extends Builder {
constructor() {
super();
console.log('ConcreteBuilder Class created!');
}
buildPart(partName) {
super.buildPart(partName);
console.log('ConcreteBuilder.buildPart invoked!');
this.product = new Product(partName);
}
getResult() {
console.log('ConcreteBuilder.getResult invoked!');
return this.product;
}
}
class Product {
constructor(material) {
console.log("Product class created");
this.data = material
}
}
class Director {
constructor() {
this.structure = ['Prod1', 'Prod2', 'Prod3'];
console.log("Director class created");
}
construct() {
console.log("Director.Construct created");
for (var prodName in this.structure) {
let builder = new ConcreteBuilder();
builder.buildPart(this.structure[prodName]);
builder.getResult();
}
}
}
let director = new Director();
director.construct();