핵심 키워드 : 코드의 목적이 잘 드러나도록 메소드의 이름을 지어 별도의 메소드로 뽑아낸다. … 1. code # BEFOR
1 2 3 4 5 |
void printOwing(double amount) { printBanner(); System.out.println("name:" + \_name); System.out.println("amount:" + amount); } |
# AFTER
1 2 3 4 5 6 7 8 9 |
void printOwning(double amount) { printBanner(); printDetail(amount); } void printDetail(double amount) { System.out.println("name:" + \_name); System.out.println("amount:" + amount); } |
example ======= # 지역변수가 없는 경우 ## befor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void printOwning() { Enumeration e = orders.elements() ; double outstanding = 0.0 ; //banner dispaly System.out.println("\ *************************"); System.out.println("***** Customer Owers****"); System.out.println("****************\ *\**\ **\***\ \*"); // outstaing 계산 while(e.hasMoreElements()) { Order each = (Order)e.nextElements(); outstanding = each.getAmount(); } //상세 정보 표시 System.out.println("name:" + \_name); System.out.println("amount:" + outstandig); } |
## […]