-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategy.js
46 lines (37 loc) · 828 Bytes
/
Strategy.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
function baseStrategy(amount)
{
return amount;
}
function premiumStrategy(amount)
{
return amount * 0.85;
}
function platinumStrategy(amount)
{
return amount * 0.65;
}
class AutoCart
{
constructor(discount)
{
this.discount = discount;
this.amount = 0;
}
checkout()
{
return this.discount(this.amount);
}
setAmount(amount)
{
this.amount = amount;
}
}
const baseCustomer = new AutoCart(baseStrategy);
const premiumCustomer = new AutoCart(premiumStrategy);
const platinumCustomer = new AutoCart(platinumStrategy);
baseCustomer.setAmount(50000);
console.log(baseCustomer.checkout());
premiumCustomer.setAmount(50000);
console.log(premiumCustomer.checkout());
platinumCustomer.setAmount(50000);
console.log(platinumCustomer.checkout());