SCJP 1.6版考題 036

出自 陳富國維基館
於 2013年3月30日 (六) 07:59 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: public class Doubler{ public static int doubleMe(Holder h){ return h.getAmount() * 2; } } and: public class Holder { int amount = 10; public void doubleA...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
public class Doubler{
     public static int doubleMe(Holder h){
        return h.getAmount() * 2;
     }
}
and:
public class Holder {
  int amount = 10;
  public void doubleAmount(){amount = Doubler.doubleMe(this);}
  public in getAmount(){return amount;}
  //more code here
}
Place the code framgmets in position to reduce the coupling between Doubler and Holder.
public class Doubler{  

  public static int doubleMe( Place here h){
    return Place here * 2;
  }
}
public class Holder {
  int amount = 10;
  public void doubleAmount(){
    amount = Doubler.doubleMe( Place here );
  }
  public in getAmount(){return amount;}
  //more code here
}


void 
Holder
int
Doubler
h.getAmount()
h
this
amount 


解答


Ans: int , h , amount

解說:

修改程式使得Doubler與Holder二個類別的耦合性降低 

Dobuler被改成不使用到Holder類別,導致Holder的變更將不影響到Doubler類別。