SCJP題庫第036題
public class Doubler{
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二個類別的耦合性降低
修改程式使得Doubler與Holder二個類別的耦合性降低
Dobuler被改成不使用到Holder類別,導致Holder的變更將不影響到Doubler類別。
Comments