3. LSP
Liskov Substitution principle (LSP; 리스코프 치환 원칙)
Liskov Substitution principle (LSP; 리스코프 치환 원칙)
위반 사례
class Rectangle {
private int width;
private int height;
public void setWidth(int width){
this.width = width;
}
public void setHeight(int height){
this.height = height;
}
public int getArea() {
return this.width * this.height;
}
}
// Test
public void testArea(Rectangle rect) {
rect.setWidth(5);
rect.setHeight(4);
System.out.println("area = " + rect.getArea()); // it must be 20.
}해결

Links
Last updated