item 51 [아이템 5] 자원을 직접 명시하지 말고 의존 객체 주입을 사용하라 SpellChecker라는 맞춤법을 검사하는 클래스가 있다. 이 클래스는 Lexicon이란 사전 클래스를 의존한다. 코드는 아래와 같다. class SpellChecker { private static final Lexicon dictionary = new KoreanDictionary(); public static boolean isValid(String word) { return true; } public static List suggestions(String typo) { return new ArrayList(); } } class KoreanDictionary implements Lexicon { } interface Lexicon { } 코드에선 KoreanDictionary를 직접 생성해서 사.. 2021. 12. 20. 이전 1 다음 728x90