아이템5 자원을 직접 명시하지 말고 의존 객체 주입을 사용하라
Effective Java 3e 아이템 5를 요약한 내용 입니다.
public class SpellChecker {
privte static final Lexion dictionary = ...;
private SpellChecker() {} // 객체 생성 방지
public static SpellChecher INSTANCE = new SpellChecker(...);
public boolean isValid(String word) { ... }
public List<String> suggertions(String type) {...}
} public class SpellChecker {
privte static final Lexion dictionary = ...;
public SpellChecker(Lexion dictionary) {
this.dictionary = Objects.requireNonNull(dictionar);
public boolean isValid(String word) { ... }
public List<String> suggertions(String type) {...}
}정리
Last updated