Skip to content

Instantly share code, notes, and snippets.

@raulmoyareyes
Created July 29, 2018 15:50
Show Gist options
  • Save raulmoyareyes/e184f926835bf3c796740b4f94a9cf98 to your computer and use it in GitHub Desktop.
Save raulmoyareyes/e184f926835bf3c796740b4f94a9cf98 to your computer and use it in GitHub Desktop.
Liskov Substitution Principle
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