1) ํด๋์ค๋ก ๋ฌถ๊ธฐ
: ํด๋ผ์ด์ธํธ๊ฐ ๊ฐ์ฒด์ ํต์ฌ ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค. ํ์ ๊ฐ์ฒด๋ค์ ์ผ๊ด๋๊ฒ ๊ด๋ฆฌํ ์ ์๋ค.
์๋ณธ ๋ฐ์ดํฐ๊ฐ ์ฝ๋ ์์์ ๊ฐฑ์ ๋ ๋ - ํด๋์ค๋ก ๋ฌถ๊ธฐ
2) ๋ณํ ํจ์๋ก ๋ฌถ๊ธฐ(6.10)
: ์๋ณธ ๋ฐ์ดํฐ๋ฅผ ์ ๋ ฅ๋ฐ์์ ํ์ํ ์ ๋ณด๋ฅผ ๋ชจ๋ ๋์ถํ ๋ค, ๊ฐ๊ฐ์ ์ถ๋ ฅ ๋ฐ์ดํฐ์ ํ๋์ ๋ฃ์ด ๋ฐํํ๋ค.
3) ์ค์ฒฉ ํจ์ ํํ๋ก ๋ฌถ๊ธฐ
: ํ ์คํธํ๊ธฐ ๊น๋ค๋ก์ธ ์ ์๋ค.
4) ํจ์๋ฅผ ๊ฐ์ฒด์ฒ๋ผ ํจํด ์ด์ฉ(ํด๋์ค ์ง์X)
1. ๊ณตํต ๋ฐ์ดํฐ ๋ ์ฝ๋๋ฅผ ์บก์ํํ๋ค.
2. ๊ณตํต ๋ ์ฝ๋๋ฅผ ์ฌ์ฉํ๋ ํจ์ ๊ฐ๊ฐ์ ์ ํด๋์ค๋ก ์ฎ๊ธด๋ค.
3. ๋ฐ์ดํฐ๋ฅผ ์กฐ์ํ๋ ๋ก์ง๋ค์ ํจ์๋ก ์ถ์ถํด์ ์ ํด๋์ค๋ก ์ฎ๊ธด๋ค.
์ด๋ ต๋ค...
// ๋ ์ฝ๋
const reading = {customer:"ivan", quantity:10, month:5, year:2017};
//๋ ์ฝ๋ ์บก์ํ
class Reading {
constructor(data){
this._customer = data.customer;
this._quantity = data.quantity;
this._month = data.month;
this._year = data.year;
}
get customer(){return this._customer;}
get quantity(){return this._quantity;}
get month(){return this._month;}
get year(){return this._year;}
get baseCharge(){
return baseRate(this.month,this.year)*this.quantity;
}
get taxableCharge(){
return Math.max(0, this.baseCharge-taxThreshold(this.year));
}
}
| 6.11. ๋จ๊ณ ์ชผ๊ฐ๊ธฐ (Split Phase) (0) | 2021.09.26 |
|---|---|
| 6.10. ์ฌ๋ฌ ํจ์๋ฅผ ๋ณํ ํจ์๋ก ๋ฌถ๊ธฐ (0) | 2021.09.26 |
| 6.8. ๋งค๊ฐ๋ณ์ ๊ฐ์ฒด ๋ง๋ค๊ธฐ (Introduce Parameter Object) (0) | 2021.09.26 |
| 6.6. ๋ณ์ ์บก์ํํ๊ธฐ (Encapsulate Variable) (0) | 2021.09.26 |
| 6.3. ๋ณ์ ์ถ์ถํ๊ธฐ (0) | 2021.09.26 |