"SCJP 1.6版考題 036" 修訂間的差異
出自 陳富國維基館
(新頁面: public class Doubler{ public static int doubleMe(Holder h){ return h.getAmount() * 2; } } and: public class Holder { int amount = 10; public void doubleA...) |
(無差異)
|
於 2013年3月30日 (六) 07:59 的最新修訂
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類別。
| ||||||||||||||||||||