아이템5. 자원을 직접 명시하지말고 의존 객체 주입을 사용하라
// 정적 유틸리티를 잘못 사용한 예 public class SpellChecker { private static final Lexicon dictionary = ...; private SpellChecker() {} public static boolean isValid(String word) {...} public static List suggestions(String typo) {...} } // 싱글톤을 잘못 사용한 예 public class SpellChecker { private final Lexicon dictionary = ...; private SpellChecker(...) {...} public static SpellChecker INSTANCE = new SpellChecker(.....
2021.06.21