checkcustomers を含む「if」ブロックは、このクラスの他のメソッドでそのまま使用されるため、同じチェックに対して多くのコード重複があります。しかし、戻り値があるため、この checksomethings を 1 つのメソッドに直接抽出することもできません。
このコードをリファクタリングするための良いアイデアはありますか? ここで単純化するためにこのコードを変更したので、このコードの小さな問題 (もしあれば) に引っかからないようにしてください。その現在の方法で多くのリターン。
public Details getCustomerDetails(){
if(checkifcustomerhasnoboobs){
..worry about it..
return new Details("no");
}
if(checkifcustomerplaytenniswell){
..do find a tennis teacher
return new Details("no cantplay");
}
//...ok now if customer passed the test, now do the some real stuff
//
//
CustomerDetails details= getCustomerDetailsFromSomewhere();
return details;
}