Created
April 15, 2015 05:16
-
-
Save efleming969/ed9139749970dfc3050a to your computer and use it in GitHub Desktop.
SOLID: Liskov Substitution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Liskov { | |
public static int calculateArea(Rectangle x) { | |
return x.getHeight() * x.getWidth(); | |
} | |
public static int calculateArea(Square x) { | |
return x.getHeight() * x.getHeight(); | |
} | |
} | |
class Rectangle { | |
private int height; | |
private int width; | |
public Rectangle (int h, int w) { | |
setHeight(h); | |
setWidth(w); | |
} | |
public void setHeight ( int value ) { | |
this.height = value; | |
} | |
public void setWidth ( int value ) { | |
this.width = value; | |
} | |
public int getHeight () { | |
return this.height; | |
} | |
public int getWidth () { | |
return this.width; | |
} | |
} | |
class Square extends Rectangle { | |
public Square ( int h, int w ) { | |
super(h, w); | |
} | |
public void setWidth ( int value ) { | |
super.setHeight(value); | |
super.setWidth(value); | |
} | |
public void setHeight ( int value ) { | |
this.setWidth(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment