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