DEV Community

loading...

Discussion on: S.O.L.I.D. Principles around You, in JavaScript

Collapse
evrtrabajo profile image
Emmanuel Valverde Ramos

I think that this code:

/* A function with such a name is a symptom of ignoring the Single Responsibility Principle
*  Validation and Specific implementation of the user creation is strongly coupled.
*  That's not good
*/ 
validateAndCreatePostgresUser = (name, password, email) => {   

  //Call an external function to validate the user form
  const isFormValid = testForm(name, password, email); 

  //Form is Valid
  if(isFormValid){
    CreateUser(name, password, email) //Specific implementation of the user creation!
  }
}

Should be somethig like:

/* A function with such a name is a symptom of ignoring the Single Responsibility Principle
*  Validation and Specific implementation of the user creation is strongly coupled.
*  That's not good
*/ 
validateAndCreatePostgresUser = (name, password, email) => {   

  // Throw an exception
  testForm(name, password, email); 

  //Specific implementation of the user creation!
  CreateUser(name, password, email);

}