Skip to content

아이템 19. 상속을 고려해 설계하고 문서화하라. 그러지 않았다면 상속을 금지하라 #45

Discussion options

You must be logged in to vote

정리 해 주신글 잘 읽었습니다. 굉장히 심오한 주제를 맡으셨군요 👍

  1. 상속용 클래스는 재정의할 수 있는 메서드들을 내부적으로 어떻게 이용하는지 문서로 남겨라

왜 굳이 문서로 남겨야 할까라는 의문이 들었는데 OOP 원칙 중 LSP가 생각이 났습니다.

LSP (Liskov Substitution Principle) 리스코프 치환 원칙)

프로그램의 객체는 프로그램의 정확성을 깨뜨리지 않으면서 하위 타입의 인스턴스로 바꿀 수 있어야 한다는 원칙

즉 부모 클래스를 상속한 자식 클래스가 메서드를 재정의할 때 상위 타입에서 의도한 기능을 벗어나버린 상황을 의미하는 즉 정확성을 깨뜨리게 재정의할 수 있는 상황을 막고자 문서로 남기는 것이 아닐까? 라는 생각을 하게 되었습니다.

  1. (효율적인 하위 클래스를 만들 수 있게) 클래스의 내부 동작 과정 중간에 끼어들 수 있는 훅을 잘 선별하여 protected 메서드 형태로 공개해야할 수 있다

참 해당 지문은 비문학 수능 시험보는 느낌이네요 😢

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@chikeem90
Comment options

chikeem90 Jan 2, 2023
Maintainer Author

@JoisFe
Comment options

Comment options

You must be logged in to vote
2 replies
@JoisFe
Comment options

@chikeem90
Comment options

chikeem90 Jan 2, 2023
Maintainer Author

Answer selected by JoisFe
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
4장 클래스와 인터페이스 이펙티브 자바 4장 (클래스와 인터페이스)
5 participants