Java 関数を避けるべき状況には、1. ネストが深すぎる、2. パラメータが多すぎる、4. リファクタリングが困難、5. 可読性が低い、などがあります。
#Java 関数の使用を避けるべき場合
Java 関数の使用を避けるべき場合Java では、関数が使用される場合があります。コードの可読性と保守性の妨げになる可能性があります。関数の使用を避けるべきいくつかの状況を次に示します。public class Example { private int calculate(int a, int b, int c, int d, int e, int f, int g, int h) { return a + b - c * d / e + f - g * h; } }
書き換え後:
public class Example { private int sum(int a, int b) { return a + b; } private int difference(int a, int b) { return a - b; } private int product(int a, int b) { return a * b; } private int quotient(int a, int b) { return a / b; } public int calculate(int a, int b, int c, int d, int e, int f, int g, int h) { return sum(a, b) - difference(c, quotient(d, e)) + difference(f, product(g, h)); } }
以上がJava 関数の使用を避けるべきなのはどのような場合ですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。