這裏是代碼...我的if,else語句很長...如何區分它?任何建議?謝謝。如何使此代碼更好地組織
public function receiveMsg(aMsg){
if($aMsg instanceof LoginMsg){
$this->callingSomeMethod(); //should I separate this code into other class/ object?
$this->callingAnotherMethod(); //should I separate this code into other class/ object?
$aMsg = new RespondLoginMsg(); //should I separate this code into other class/ object?
$this->sendMsg($aMsg); //should I separate this code into other class/ object?
}else if(aMsg instanceof LogoutMsg){
$this->callingSomeMethod(); //should I separate this code into another class/ object?
$aMsg = new RespondLogoutMsg(); //should I separate this code into another class/ object?
$this->sendMsg($aMsg); //should I separate this code into another class/ object?
}else if/*****bababab***/
/*****many else if here (up to 200 msg+ , just upload 2 here.)***/
}
不,你可以看到,第二個是RespondLogoutMsg而不是RespondLoginMsg ..... – Tattat
啊哈。錯過了,對不起。 – craigmc