Created
April 18, 2018 19:55
-
-
Save kudapara/031caff01b0920e3105fbdf99ac24716 to your computer and use it in GitHub Desktop.
Code that adheres to DIP
This file contains 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 Shape { | |
constructor () {} | |
setColor (color) { | |
this.color = color | |
} | |
} | |
class Triangle extends Shape { | |
constructor (base, height) { | |
this.base = base | |
this.height = height | |
} | |
} | |
} | |
class Square extends Shape { | |
constructor (length) { | |
this.length = length | |
} | |
} | |
class Picture { | |
constructor (shape, color) { | |
this.shape = shape | |
this.shape.setColor(color) | |
} | |
} | |
const triangle = new Triangle(5, 10) | |
const square = new Square(5) | |
const trianglePicture = new Picture(triangle, 'blue') | |
const squarePicture = new Picture(square, 'blue') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment