SCJP題庫第036題



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
解說:
修改程式使得DoublerHolder二個類別的耦合性降低 




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

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度