<자바로 배우는 리팩토링 입문> 4장~6장
BFine
4장. 널 객체 a. 일반 null - Person이라는 클래스 안에는 Dog라는 클래스를 가지고 있다. Person은 Dog를 하나만 가질 경우에는 dog2 에는 null을 입력한다. class Person{ private final Dog dog1; private final Dog dog2; public Person(Dog dog1, Dog dog2){ this.dog1 = dog1; this.dog2 = dog2; } public Person(Dog dog1){ this(dog1, null); } } b. 널객체 도입 - 위의 코드에 널객체를 도입해보자. Dog 클래스에 isNull() 메서드를 추가한다. - 그리고 NullDog이라는 클래스를 생성하고 상속받아서 isNull() 메서드를 Overr..