-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactoryMethod.js
More file actions
40 lines (36 loc) · 922 Bytes
/
factoryMethod.js
File metadata and controls
40 lines (36 loc) · 922 Bytes
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
/* Minimum factory has :
* A constructor class that generates an object
* A class that calls this creation with the given parameters
*/
class ProductItem {
constructor({ ...itemProperties }) {
var { itemType, itemPrice, itemUrl, itemValue } = itemProperties;
this.itemPrice = itemPrice;
this.itemUrl = itemUrl;
this.itemValue = itemValue;
this.itemType = itemType;
}
}
class ProductItemFactory {
create(type) {
if (type === 'laptop') {
return new ProductItem({
itemType: 'laptop',
itemUrl: 'https://test.addr.com',
itemValue: null,
});
}
if (type === 'pc') {
return new ProductItem({
itemType: 'pc',
itemUr: 'https://test.addr.com',
itemValue: null,
});
}
}
}
var productFactory = new ProductItemFactory();
var asusRogStrix = productFactory.create('laptop');
var pcInstance = productFactory.create('pc');
console.log(asusRogStrix);
console.log(pcInstance);