-
Notifications
You must be signed in to change notification settings - Fork 75
/
Factory.js
45 lines (36 loc) · 874 Bytes
/
Factory.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
'use strict';
class Product {
constructor() {
console.log('Product Class created');
}
}
class ConcreteProduct extends Product {
constructor() {
super();
console.log('ConcreteProduct Class created');
}
}
class Creator {
constructor() {
console.log('Creator Class created');
}
factoryMethod() {
console.log('Creator.factoryMethod created');
}
anOperation() {
console.log('Creator.anOperation created');
this.product = this.factoryMethod();
console.log(this.product instanceof ConcreteProduct);
}
}
class ConcreteCreator extends Creator {
constructor() {
super();
console.log('ConcreteCreator Class created');
}
factoryMethod() {
return new ConcreteProduct();
}
}
var factory = new ConcreteCreator();
factory.anOperation();