Last active
January 18, 2019 02:33
-
-
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
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 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