2014-11-25 3 views
1

내부 클래스에서 외부 클래스 '메서드를 호출 한 다음 외부 클래스에서 내부 클래스'메서드를 사용하는 것이 나쁜 습관으로 간주되는지 궁금합니다. 이 경우 내부 클래스는 외부 클래스의 메서드를 사용합니다. 그 Cyclic 참조입니까? How to avoid

: I의 방법을 외부 클래스에 속한 updateMaps()를 호출 BidParser 있다. 또한 BidParser 두 번째 내부 클래스 InputSanityChecker의 메서드를 호출합니다.

나쁜 습관과 반 패턴입니까? 여기 하나님의 객체를 생성하고 있습니까 (더 많은 기능을하지만 다른 외부 클래스에 따라)

편집 : 나는 두 변수 VAR1, 변수 2를 대입 할 때 변수가 오전 바깥에 속하지만 updateX에 필요한 것을 (의 말을하자) 및 checkX 메소드.

public class Outer{ 


    public static void main(String[] args){ 
     if(args.length == 1){ 
      File file = new File(args[0]); 
      BidParser.parseBids(file);//<--- Question refers here 
     }else{ 
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
      BidParser.parseBids(br); //<--- and here 
     } 
    } 


    private static void updateMaps(String[] elements){ 
     //.....blah blah 
    } 

    static class BidParser{ 
     public static void parseBids(File file){ 
      //.....blah blah 
      InputSanityChecker.checkInput(elems);//<---second inner class method 
      InputSanityChecker.checkMaps(elems); //<---second inner class method 
      updateMaps(elems); //<-----outer class method 

     } 
     public static void parseBids(Reader reader){ 
      //.....blah blah 
      InputSanityChecker.checkInput(elems);//<---second inner class method 
      InputSanityChecker.checkMaps(elems); //<---second inner class method 
      updateMaps(elems); //<-----outer class method 

     } 
     } 
    static class InputSanityChecker{ 

     public static boolean checkInput(String[] elements){ 
       //.....blah blah 
     } 

     public static boolean checkMaps(String[] elements){ 
       //.....blah blah 
     } 
    } 
} 
+3

* inner * 클래스를 사용하고 있지 않습니다. 당신은 단순히 * member * 클래스를 사용하고 있습니다. 이 클래스들을'static'으로 선언했기 때문입니다. * inner * 클래스 또는 static이 아닌 클래스; 그것들은 생성 된 외부 클래스의 인스턴스에 대한 링크를 가지고 있기 때문에 내부 클래스입니다. –

+0

둘째, BidParser에서 'checkInput (elems);'호출이 유효하지 않습니다 (컴파일러 오류가 발생합니다). 'InputSanityChecker.checkInput (elems);이어야합니다. –

+0

@ErwinBolwidt는 오류에 대해 걱정하지 않습니다. 필자는 실제 코드에서 많은 것을 추상화하여 구조를 볼 수 있습니다. 그러나 당신이 옳다. 나는 명확하게 그것을 바꿀 것이다. – MayTheSchwartzBeWithYou

답변