-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8-2-Customer.js
58 lines (50 loc) Β· 1.12 KB
/
8-2-Customer.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
/**
* p291 μμ
*/
class Customer {
#name;
#contract;
constructor(name, discountRate) {
this.#name = name;
this.#contract = new CustomerContract(dateToday());
this.#setDiscountRate(discountRate);
}
get discountRate() {
return this.#contract.discountRate;
}
#setDiscountRate(aNumber) {
this.#contract.discountRate = aNumber;
}
becomePreferred() {
this.#setDiscountRate(this.discountRate + 0.03);
// λ€λ₯Έ λ©μ§ μΌλ€
}
applyDiscount(amount) {
return amount.subtract(amount.multiply(this.discountRate));
}
}
class CustomerContract {
#startDate;
#discountRate;
constructor(startDate, discountRate) {
this.#startDate = startDate;
this.#discountRate = discountRate;
}
get discountRate() {
return this.#discountRate;
}
set discountRate(arg) {
this.#discountRate = arg;
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
function dateToday() {
return '2022-11-19';
}
const name = 'λ§ν΄ νμΈλ¬';
const discountRate = 0.1;
const customer = new Customer(name, discountRate);
customer.becomePreferred();
console.log(customer.discountRate);