z********i 发帖数: 568 | 1 为什么会比switch statements好?
Switch statements:
public boolean beats(GameObject object){
if(object.getClass.getName(0.equals("Rock"){
result=false;
}
else if(object.getClass.getName(0.equals("Rock"){
result=false;
}else if(object.getClass.getName(0.equals("Rock"){
result=false;
}
return result;
}
Doulbe Dispatch Pattern:
public class Rock implements GameObject{
public boolean beats(GameObject o){
return o.beatsRock();
}
public beatsRock(){
return false;
}... 阅读全帖 |
|