Skip to content

Instantly share code, notes, and snippets.

@rxluz
Last active January 18, 2019 02:33
Show Gist options
  • Save rxluz/ac8345d7df2c68989bd9e6767425eb3b to your computer and use it in GitHub Desktop.
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
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