daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ValidateEmailSimple {
  2.   isValid(email) {
  3.     return email.indexOf("@") > 2;
  4.   }
  5. }
  6.  
  7. class ValidateEmailAdvanced {
  8.   isValid(email) {
  9.     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,}))$/;
  10.     return re.test(String(email).toLowerCase());
  11.   }
  12. }
  13.  
  14. class Client {
  15.   constructor({ name, email, address, ValidateEmailService }) {
  16.     this._emailValidationService = ValidateEmailService;
  17.  
  18.     this.setName(name);
  19.     this.setEmail(email);
  20.     this.setAddress(address);
  21.   }
  22.  
  23.   setName(name) {
  24.     this.name = name;
  25.   }
  26.  
  27.   setEmail(email) {
  28.     if (this._emailValidationService.isValid(email)) {
  29.       this.email = email;
  30.     }
  31.   }
  32.  
  33.   setAddress(address) {
  34.     this.address = address;
  35.   }
  36. }
  37.  
  38. class ClientFacade {
  39.   constructor({ name, email, address }) {
  40.     const ClientInstance = new Client({
  41.       name,
  42.       email,
  43.       address,
  44.       ValidateEmailService: new ValidateEmailSimple(),
  45.     });
  46.  
  47.     return ClientInstance;
  48.   }
  49. }
  50.  
  51. const run = () => {
  52.   const ClientInstance = new ClientFacade({
  53.     name: "Some client name",
  54.     email: "email@email.com",
  55.     address: "addresss",
  56.   });
  57.  
  58.   console.log(ClientInstance);
  59. };
  60.  
  61. run();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top