OOP
리스코프 치환 원칙(Liskov Substitution Principle, LSP)
설명 상속 관계에 있는 클래스들이 서로를 대체 할 수 있다는 원칙입니다. S가 T의 하위 타입이라면 T 타입의 객체를 S 타입의 객체로 대체해도 프로그램의 동작이 변경되지 않아야 합니다. 서브 클래스는 슈퍼 클래스의 기능을 변경하지 않고 확장하여야 하며, 이를 통해 프로그램의 일관성을 유지하고 안정성을 확보할 수 있습니다. Bad Case public class Rectangle { protected int width; protected int height; public Rectangle(int width, int height) { this.width = width; this.height = height; } public int getWidth() { return width; } public void s..
2024. 3. 10. 15:30