OK...
Thanks to your help, I created a Factory method that returns an object according to type.
public class ActionFactory {
public static Action createAction(JSONObject object){
try{
String username = object.getString("USERNAME");
String type = object.getString("TYPE");
String src= object.getString("SRC");
String dest = object.getString("DEST");
if(type == "MOVE"){
return new ActionMove(username,src,dest);
}
else if(type == "KILL"){
return new ActionKill(username,src,dest);
}
else if(type == "DIED"){
return new ActionDied(username, src, dest);
}
else if(type == "TIE"){
}
}
catch(JSONException e){
e.printStackTrace();
}
return null;
}
}
source
share