Skip to content

Instantly share code, notes, and snippets.

View rxluz's full-sized avatar

Ricardo Luz rxluz

View GitHub Profile
@rxluz
rxluz / SOLID_DIPExample.js
Last active January 18, 2019 03:22
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class ValidateEmailSimple {
isValid(email) {
return email.indexOf("@") > 2;
}
}
class ValidateEmailAdvanced {
isValid(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
@rxluz
rxluz / SOLID_DIPViolationExample.js
Last active January 18, 2019 02:32
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class ValidateEmailSimple {
isValid(email) {
return email.indexOf("@") > 2;
}
}
class ValidateEmailAdvanced {
isValid(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
@rxluz
rxluz / SOLID_ISPExample.js
Last active January 18, 2019 03:15
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Product {
setName({ name, onFinish = () => {} }) {
this.name = name;
onFinish(this);
}
}
const run = () => {
const ProductInstance = new Product();
@rxluz
rxluz / SOLID_ISPViolationExample.js
Last active January 18, 2019 02:32
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Product {
setName({ name, onFinish }) {
this.name = name;
onFinish(this);
}
}
const run = () => {
const ProductInstance = new Product();
@rxluz
rxluz / SOLID_LSPExample.js
Last active January 18, 2019 02:33
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Retangle {
constructor({ width, length }) {
this.setWidth(width);
this.setLength(length);
}
setWidth(width) {
this.width = width;
}
@rxluz
rxluz / SOLID_LSPViolationExample.js
Last active January 18, 2019 02:33
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Retangle {
constructor({ width, length }) {
this.setWidth(width);
this.setLength(length);
}
setWidth(width) {
this.width = width;
}
@rxluz
rxluz / SOLID_OCPExample.js
Last active January 18, 2019 02:33
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);
@rxluz
rxluz / SOLID_OCPViolationPrinciple.js
Last active January 18, 2019 02:33
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class Sandwich {
constructor({ name, size, price } = {}) {
this.setName(name);
this.setSize(size);
this.setPrice(price);
}
setName(name) {
this.name = name;
}
@rxluz
rxluz / SOLID_SRPExample.js
Last active January 18, 2019 02:34
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class User {
constructor(name, age) {
this.name = name;
this.age = age;
}
setName(name) {
this.name = name;
}
@rxluz
rxluz / SOLID_SRPViolationPrincipleExample.js
Last active January 18, 2019 02:34
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
class User {
constructor(name, age) {
this.name = name;
this.age = age;
this.logs = [];
}
setName(name) {
this.name = name;
this.logs.push("Edited user name");