코드 3-10 If/Else가 넘쳐나는 코드의 예
public UpdateResult UpdateCityIfChanged() {
if (Id > 0) {
bool isActive = db.IsPersonActive(Id);
if (isActive) {
if (FirstName != null && LastName != null) {
string normalizedFirstName = FirstName.ToUpper();
string normalizedLastName = LastName.ToUpper();
string currentCity = db.GetCurrentCityByName(
normalizedFirstName, normalizedLastName);
if (currentCity != City) {
bool success = db.UpdateCurrentCity(Id, City);
if (success) {
return UpdateResult.Success;
} else {
return UpdateResult.UpdateFailed;
}
} else {
return UpdateResult.CityDidNotChange;
}
} else {
return UpdateResult.InvalidName;
}
} else {
return UpdateResult.PersonInactive;
}
} else {
return UpdateResult.InvalidId;
}
}