거부당한 유산
코드 악취 중 하나. 하위 클래스가 상위 클래스의 메서드와 데이터 중 일부만 사용하는 현상. 상속 관계가 잘못되었기 때문일 가능성이 있다.
약한 냄새
냄새가 심하지 않으면 그냥 두기:
We do subclassing to reuse a bit of behavior all the time, and we find it a perfectly good way of doing business. There is a smell—we can’t deny it—but usually it isn’t a strong smell. So, we say that if the refused bequest is causing confusion and problems, follow the traditional advice. However, don’t feel you have to do it all the time. Nine times out of ten this smell is too faint to be worth cleaning. —Chapter 3, Refactoring: Improving the design of existing code
관련 리팩토링
- Push down method
- Push down field
- Replace subclass with delegate
- Replace superclass with delegate