-1
내 클래스에는 복잡한 메서드가 있습니다.이 메서드에서는 여러 메서드를 호출하고 인스턴스 변수를 전달했지만 매개 변수로 6 개 이상의 인스턴스 변수도 전달했습니다.전역 인스턴스 변수 또는 로컬 인스턴스 변수 선언 Java에서 어느 것이 더 낳았는지
나는 전역 인스턴스 변수로 그 인스턴스 매개 변수를 선언하여 메서드 내에서 직접 액세스 할 수 있다고 생각했습니다.
글로벌 인스턴스 변수를 사용하는 것이 더 나은 방법입니까? 예를 들어
:
Process 1 :
public class PostIncExample {
public void test() {
Test1 test = findById();
Test2 test2 = findOne();
Test3 test3 = fildOne();
Lis<Test4> test4 = findAll();
}
private void redemp(Test1 test, Test2 test2, Test3 test3, Lis<Test4> test4) {
}
private void accuM(Test1 test, Test2 test2, Test3 test3, Lis<Test4> test4) {
}
}
Process 2 :
public class PostIncExample {
Test1 test;
Test2 test2;
Test3 test3;
Lis<Test4> test4;
public void test() {
test = findById();
test2 = findOne();
test3 = fildOne();
test4 = findAll();
}
private void redemp() {
// Used above instance directly here
}
private void accuM() {
// Used above instance directly here
}
}
어떤 프로세스가 더 낫다?