Skip to content

Instantly share code, notes, and snippets.

@rxluz
Last active January 18, 2019 02:33
Show Gist options
  • Save rxluz/52f901c42c5f59045087e1db84a71f2d to your computer and use it in GitHub Desktop.
Save rxluz/52f901c42c5f59045087e1db84a71f2d 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 {
constructor(side) {
this.setSide(side);
}
setSide(side) {
this.side = side;
}
getSide() {
return this.side;
}
getArea() {
return this.side * this.side;
}
}
const run = () => {
const SquareInstance = new Square(7);
console.log(SquareInstance.getArea()); // will output 49
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment