forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructural_facade.js
More file actions
69 lines (57 loc) · 1.22 KB
/
structural_facade.js
File metadata and controls
69 lines (57 loc) · 1.22 KB
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
const FACADE = {
id: 'facade',
name: 'Facade',
type: 'structural',
hint: 'A single class that represents an entire subsystem',
definition: `Provide a unified interface to a set of interfaces in a subsystem.
Facade defines a higher-level interface that makes the subsystem easier to use.`,
when: `you want to provide a simple interface to a complex subsystem`,
codeES5: `var shopPattern = {
calc: function(price) {
price = discount(price);
price = fees(price);
price += shipping();
return price;
}
};
function discount(value) {
return value * 0.9;
}
function shipping() {
return 5;
}
function fees(value) {
return value * 1.05;
}
module.exports = shopPattern;`,
codeES6: `class ShopPattern {
constructor() {
this.discount = new Discount();
this.shipping = new Shipping();
this.fees = new Fees();
}
calc(price) {
price = this.discount.calc(price);
price = this.fees.calc(price);
price += this.shipping.calc();
return price;
}
}
class Discount {
calc(value) {
return value * 0.9;
}
}
class Shipping {
calc() {
return 5;
}
}
class Fees {
calc(value) {
return value * 1.05;
}
}
export default ShopPattern;`
};
export default FACADE;