我有一個代碼塊,我有一個問題,減少了圈複雜度。由於需要匹配的多重條件,我不確定將其分解的最佳方式。更爲複雜的是,在其中兩種情況下創建了一個新的對象,但不是在第三種情況下(它會調用另一種方法)。這是僞代碼:環複雜度減少
if (!cond3 && !cond1 && cond2 && cond4) {
// actions to perform
calculateValues();
return result;
} else if (!cond1 && cond2 && cond3) {
// actions to perform
Object result = new Result();
return result;
} else if (!cond4 && cond3 && cond1 && cond5) {
// actions to perform
Object result = new Result();
return result;
} else {
// throw error because inputs are invalid
}
對我來說很好。 –
@LouisWasserman,是諷刺嗎? – jaco0646
@ jaco0646,不,它不是。 –