你認爲將重構這種布爾方法的最佳方式是什麼?布爾multireturn重構
if (someService.isTrue(importantArg)) {
return true;
} else if (someService.isSomeTrue(anotherArg)) {
return isAnotherCondition(entry);
} else {
return super.thisMethod();
}
你認爲將重構這種布爾方法的最佳方式是什麼?布爾multireturn重構
if (someService.isTrue(importantArg)) {
return true;
} else if (someService.isSomeTrue(anotherArg)) {
return isAnotherCondition(entry);
} else {
return super.thisMethod();
}
return someService.isTrue(importantArg) || (someService.isSomeTrue(anotherArg)
&& isAnotherCondition(entry)) || super.thisMethod();
您聲稱這是可讀的嗎? –
@BoristheSpider不,但是op沒有要求任何更可讀的東西。他想重構它。所以我假裝最短的解決方案 – Paul
我從來沒有聽說過重構使代碼無法讀取。所以我會建議這不能回答這個問題。 –
這是一個小重構,但你可以刪除別人的,你不能達到這個代碼,如果以前的狀態是真實的(如果它是真實的,它會返回一個值,並退出方法)
if (someService.isTrue(importantArg)) {
return true;
}
if (someService.isSomeTrue(anotherArg)) {
return isAnotherCondition(entry);
}
return super.thisMethod();
它爲什麼需要重構? –
你認爲這種多回歸混亂是可以接受的嗎? – sidlejinks