Last active
January 18, 2019 02:32
-
-
Save rxluz/c80a83dd7e231e3e5f6ffe0446e4f5e5 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 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()); | |
} | |
} | |
class Client { | |
constructor({ name, email, address }) { | |
this.setName(name); | |
this.setEmail(email); | |
this.setAddress(address); | |
} | |
setName(name) { | |
this.name = name; | |
} | |
setEmail(email) { | |
const ValidadeEmailInstance = new ValidateEmailSimple(); | |
if (ValidadeEmailInstance.isValid(email)) { | |
this.email = email; | |
} | |
} | |
setAddress(address) { | |
this.address = address; | |
} | |
} | |
const run = () => { | |
const ClientInstance = new Client({ | |
name: "Some client name", | |
email: "[email protected]", | |
address: "addresss", | |
}); | |
console.log(ClientInstance); | |
}; | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment