let temp = 2 * (height + width);
console.log(temp);
temp = height * width;
console.log(temp);
const perimeter = 2 * (height + width);
console.log(perimeter);
const area = height * width;
console.log(area);
Encapsulate Record
)Change Function Declaration
)class Organization {
get name() {...}
}
class Organization {
get title() {...}
}
Replace Derived Variable with Query
Split Variables
)를 활용해 각 갱신 지점에서 변수를 분리한다.Encapsulate Variables
)를 적용하여 Assertion이 들어갈 장소를 마련한다.Remove Dead Code
)로 없앤다.get discountedTotal() {return this._discountedTotal;}
set discount(aNumber) {
const old = this._discount;
this._discount = aNumber;
this._discountedTotal += old - aNumber;
}
get discountedTotal() {return this._baseTotal - this._discount;}
set discount(aNumber) {this._discount = aNumber;}
class Product {
applyDiscount(arg) {this._price.amount -= arg;}
class Product {
applyDiscount(arg) {
this._price = new Money(this._price.amount - arg, this._price.currency);
}
let customer = new Customer(customerData);
let customer = customerRepository.get(customerData.id);
function potentialEnergy(mass, height) {
return mass * 9.81 * height;
}
const STANDARD_GRAVITY = 9.81;
function potentialEnergy(mass, height) {
return mass * STANDARD_GRAVITY * height;
}
블로그를 통해 코드 리팩토링에 관한 여러 가지 방법을 알게 되어 정말 유익했습니다. 특히 '변수 쪼개기'와 '매직 리터럴 바꾸기'에 대한 설명이 인상 깊었습니다. 감사합니다.