Skip to content

Instantly share code, notes, and snippets.

@kudapara
Created April 18, 2018 19:55
Show Gist options
  • Save kudapara/031caff01b0920e3105fbdf99ac24716 to your computer and use it in GitHub Desktop.
Save kudapara/031caff01b0920e3105fbdf99ac24716 to your computer and use it in GitHub Desktop.
Code that adheres to DIP
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