Questions tagged «local-variable»

8
“变量应尽可能地处于最小范围内”是否包括“变量应尽可能不存在”的情况?
根据有关“ 原理变量比实例变量更喜欢局部变量? ” 的公认答案,变量应处于尽可能小的范围内。 将问题简化为我的解释,这意味着我们应该重构这种代码: public class Main { private A a; private B b; public ABResult getResult() { getA(); getB(); return ABFactory.mix(a, b); } private getA() { a = SomeFactory.getA(); } private getB() { b = SomeFactory.getB(); } } 变成这样的东西: public class Main { public ABResult getResult() { A …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.