Created
July 29, 2018 15:50
-
-
Save raulmoyareyes/e184f926835bf3c796740b4f94a9cf98 to your computer and use it in GitHub Desktop.
Liskov Substitution Principle
This file contains 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 Rectangle { | |
constructor(width, height) { | |
this.width = width; | |
this.height = height; | |
} | |
getArea() { | |
return this.width * this.height; | |
} | |
} | |
class Square extends Rectangle { | |
constructor(size) { | |
super(size, size); | |
} | |
} | |
function renderLargeRectangles(rectangles) { | |
rectangles.forEach((rectangle) => { | |
const area = rectangle.getArea(); | |
}); | |
} | |
const rectangles = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(4)]; | |
renderLargeRectangles(rectangles); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment