멤버 자원이 클래스 동작에 영향을 준다면 싱글턴정적 유틸리티 클래스를 사용하지말고, 의존 객체 주입을 하도록 하자.

의존성 주입

class SpellChecker {
  private final Lexicon dictionary;

  SpellChecker(Lexicon dictionary) {
    this.dictionary = Objects.requireNonNull(dictionary);
  }

  boolean isValid(String word) { ... }
}

잘못된 정적 유틸리티

class SpellChecker {
  private static final Lexicon dictionary = ...;

  private SpellChecker() {}

  boolean static isValid(String word) { ... }
}

잘못된 싱글턴

class SpellChecker {
  private final Lexicon dictionary = ...;
  public static final SpellChecker INSTANCE = new SpellChecker();

  private SpellChecker() {}

  boolean static isValid(String word) { ... }
}