あなたは3つの条件をチェックする必要があり、場合によっては、この例のように、同じ値を返す場合:可読性の点でどちらが優れていますか?
if (designatorType != AttributeDesignator.ENVIRONMENT_TARGET)
return new EvaluationResult(BagAttribute.
createEmptyBag(attributeType));
if (! attributeId.toString().equals("processor-load"))
return new EvaluationResult(BagAttribute.
createEmptyBag(attributeType));
if (! attributeType.toString().equals(IntegerAttribute.identifier))
return new EvaluationResult(BagAttribute.
createEmptyBag(attributeType));
は、この
if (designatorType != AttributeDesignator.ENVIRONMENT_TARGET) ||
(! attributeId.toString().equals("processor-load")) ||
(! attributeType.toString().equals(IntegerAttribute.identifier)) ||
return new EvaluationResult(BagAttribute.
createEmptyBag(attributeType));
このようにそれを書き直すほうがよいのではないだろうおそらく非常に主観的ですが、私はまだ誰かが有効な答えを与えることを願っています:-)。
これは主観的な質問ですが、メソッドのreturn文の数を減らすために2番目のオプションを使用します。 – MByD
私の2セントは、後者が理解しやすいことです。前者は目が簡単ですが、後者の方がいいです。 – Dois