-
Notifications
You must be signed in to change notification settings - Fork 75
/
AbstractFactory.js
97 lines (80 loc) · 2.09 KB
/
AbstractFactory.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
class AbstractFactory {
constructor() {
console.log("AbstractFactory class created");
}
createProductA(product) {
console.log("AbstractFactory.createProductA created");
}
createProductB(product) {
console.log("AbstractFactory.createProductB created");
}
}
class ConcreteFactory1 extends AbstractFactory {
constructor() {
super();
console.log("ConcreteFactory1 class created");
}
createProductA(product) {
console.log('ConcreteFactory1 createProductA');
return new ProductA1();
}
createProductB(product) {
console.log('ConcreteFactory1 createProductB');
return new ProductB1();
}
}
class ConcreteFactory2 extends AbstractFactory {
constructor() {
super();
console.log("ConcreteFactory2 class created");
}
createProductA(product) {
console.log('ConcreteFactory2 createProductA');
return new ProductA2();
}
createProductB(product) {
console.log('ConcreteFactory2 createProductB');
return new ProductB2();
}
}
class AbstractProductA {
constructor() {
console.log('AbstractProductA class created');
}
}
class AbstractProductB {
constructor() {
console.log('AbstractProductB class created');
}
}
class ProductA1 extends AbstractProductA {
constructor() {
super();
console.log('ProductA1 class created');
}
}
class ProductA2 extends AbstractProductA {
constructor() {
super();
console.log('ProductA2 class created');
}
}
class ProductB1 extends AbstractProductB {
constructor() {
super();
console.log('ProductB1 class created');
}
}
class ProductB2 extends AbstractProductB {
constructor() {
super();
console.log('ProductB2 class created');
}
}
var factory1 = new ConcreteFactory1();
var productB1 = factory1.createProductB();
var productA1 = factory1.createProductA();
var factory2 = new ConcreteFactory2();
var productA2 = factory2.createProductA();
var productB2 = factory2.createProductB();