Last active
January 18, 2019 02:33
-
-
Save rxluz/ac8345d7df2c68989bd9e6767425eb3b 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 Sizes { | |
constructor() { | |
this.data = ["small", "medium", "big"]; | |
return this.data; | |
} | |
} | |
class Sandwich { | |
constructor({ name, size, price } = {}) { | |
this.setName(name); | |
this.setSize(size); | |
this.setPrice(price); | |
} | |
setName(name) { | |
this.name = name; | |
} | |
setPrice(price) { | |
this.price = price; | |
} | |
setSize(size) { | |
const sizesList = new Sizes(); | |
if (sizesList.includes(size)) { | |
this.size = size; | |
} | |
} | |
} | |
const run = () => { | |
const TunaSandwich = new Sandwich({ | |
name: "Tuna Sandwich", | |
size: "medium", | |
price: 2.5, | |
}); | |
console.log(TunaSandwich); | |
}; | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment