public class SpellChecker {
private static final Lexicon dictionary = ...; // 정적으로 초기화
private SpellChecker() {} // 객체 생성 방지
public static boolean isValid(String word) { ... }
public static List<String> suggestions(String typo) { ... }
}
⇒ 유연하지 않고 테스트하기 어려움!
SpellChecker
클래스가 내부적으로 사용하는 dictionary
객체가 정적으로 초기화dictionary
에 의존하는 메서드들(isValid
, suggestions
)을 격리시켜 테스트하기가 매우 어려움.public class SpellChecker {
private final Lexicon dictionary = ...;
private SpellChecker(...) {}
public static SpellChecker INSTANCE = new SpellChecker(...);
public boolean isValid(String word) { ... }
public List<String> suggestions(String typo) { ... }
}
⇒ 마찬가지로 유연하지 않고 테스트하기 어려움!!
SpellChecker
클래스는 싱글턴 패턴을 통해 오직 하나의 인스턴스만을 생성하고 이를 전역적으로 사용함dictionary
)를 내부적으로 유지하므로, 각 테스트 간에 상태를 초기화하거나 변경하기 어려움**클래스(SpellChecker)**가 여러 자원 인스턴스를 지원해야 하며, 클라이언트가 원하는 자원(dictionary)을 사용하게 하려면 어떻게 해야할까?