Created
March 5, 2023 10:05
-
-
Save Hyodori04/13f1648411bac26280c460109bc4d259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 절차 | |
1. 다형 메서드 인지 확인한다 (서브 클래스에서 오버라이드하는 메서드는 인라인하면 안된다) | |
2. 인라인할 함수를 호출하는 곳을 모두 찾는다. | |
3. 각 호출문을 함수 본문으로 교체한다. | |
4. 하나씩 교체할 때마다 테스트한다. | |
5. 함수 정의(원래 함수)를 삭제한다. | |
*/ | |
/// 예시 1 | |
// before | |
function rating(aDriver) { | |
return moreThanFiveLateDeliveries(aDriver) ? 2 : 1; | |
} | |
function moreThanFiveLateDeliveries(dvr) { | |
return dvr.numberOfLateDeliveries > 5; | |
} | |
// after | |
function rating(aDriver) { | |
aDriver.numberOfLateDeliveries > 5 ? 2 : 1; | |
} | |
// 예시 2 | |
// before | |
function reportLines(aCustomer){ | |
const lines = []; | |
gatherCustomerData(lines, aCustomer); | |
return lines | |
} | |
function gatherCustomerData(out, aCustomer) { | |
out.push(["name", aCustomer.name]) | |
out.push(["location", aCustomer.location]) | |
} | |
// 인라인은 단계별로 처리해라! | |
// after 1 | |
function reportLines(aCustomer) { | |
const lines = []; | |
lines.push(["name", aCustomer.name]) | |
gatherCustomerData(out, aCustomer) | |
return lines | |
} | |
function gatherCustomerData(out, aCustomer) { | |
out.push(["location", aCustomer.location]) | |
} | |
// 인라인은 단계별로 처리해라! | |
// after 2 | |
function reportLines(aCustomer) { | |
const lines = []; | |
lines.push(["name", aCustomer.name]) | |
lines.push(["location", aCustomer.location]) | |
return lines | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment