Skip to content

Instantly share code, notes, and snippets.

@rxluz
Last active January 18, 2019 02:33
Show Gist options
  • Save rxluz/a50019c80acf511d228b985dddcad438 to your computer and use it in GitHub Desktop.
Save rxluz/a50019c80acf511d228b985dddcad438 to your computer and use it in GitHub Desktop.
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Retangle {
constructor({ width, length }) {
this.setWidth(width);
this.setLength(length);
}
setWidth(width) {
this.width = width;
}
setLength(length) {
this.length = length;
}
getWidth() {
return this.width;
}
getLength() {
return this.length;
}
getArea() {
return this.width * this.length;
}
}
class Square extends Retangle {
constructor(length) {
super({ width: length, length });
}
getArea() {
return this.length * this.length;
}
}
const run = () => {
const RetangleInstance = new Retangle({ width: 10, length: 5 });
const SquareInstance = new Square(10);
SquareInstance.setLength(5);
SquareInstance.setWidth(7);
console.log(SquareInstance.getArea()); //expected: 35, receiveid: 25
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment