10장 상속과 코드 재사용
오브젝트의 10장을 요약한 내용 입니다.
상속과 중복 코드
DRY 원칙
중복과 변경
강하게 결합된 Phone과 NightlyDiscountPhone
public class Phone {
private double taxRate; // 세금 부과 요구사항으로 인한 변수 추가
public Phone(Money amount, Duration seconds, double taxRate) {
...
this.taxTate = taxRate;
}
public calculateFee() {
...
return result.plus(result.times(taxRate));
}
public double getTaxRate() {
return this.taxRate;
}
}취약한 기반 클래스 문제
불필요한 인터페이스 상속 문제

메서드 오버라이딩의 오작용 문제
Phone 다시 살펴보기
추상화에 의존하자
중복 코드를 부모 클래스로 올려라

차이에 의한 프로그래밍
정말로 필요한 경우에만 상속을 사용하라
Last updated