由买买提看人间百态

topics

全部话题 - 话题: gameobject
(共0页)
z********i
发帖数: 568
1
来自主题: JobHunting版 - Double Dispatch Pattern vs. Switch
为什么会比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;
}... 阅读全帖
(共0页)