forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19cc5c9
commit 695c618
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
Roadmap/26 - SOLID SRP/javascript/JesusAntonioEEscamilla.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** #26 - JavaScript -> Jesus Antonio Escamilla */ | ||
|
||
/** | ||
* Los principios SOLID son un conjunto de cinco principios de diseño orientados a objetos que buscan hacer | ||
el software más comprensible, flexible y mantenible. | ||
* Principio de Responsabilidad Única (Single Responsibility Principle - SRP) | ||
* Una clase debe tener una, y solo una, razón para cambiar. En otras palabras, una clase debe tener una | ||
única responsabilidad o propósito. | ||
*/ | ||
|
||
//---EJERCIÓ--- | ||
// INCORRECTA | ||
class User_Incorrecto{ | ||
constructor(nombre, email){ | ||
this.nombre = nombre, | ||
this.email = email | ||
}; | ||
|
||
getUserData(){ | ||
return{ | ||
nombre: this.nombre, | ||
email: this.email | ||
}; | ||
} | ||
|
||
saveToDatabase(){ | ||
console.log(`Guardando el usuario ${this.nombre} en la base de datos`); | ||
} | ||
} | ||
|
||
// Uso del ejemplo Incorrecto | ||
const user1 = new User_Incorrecto('Jesus', '[email protected]'); | ||
console.log(user1.getUserData()); | ||
user1.saveToDatabase(); | ||
|
||
// CORRECTO | ||
class User_Correcto{ | ||
constructor(nombre, email){ | ||
this.nombre = nombre; | ||
this.email = email; | ||
} | ||
|
||
getUserData(){ | ||
return{ | ||
nombre: this.nombre, | ||
email: this.email | ||
}; | ||
} | ||
} | ||
|
||
class UserRepository{ | ||
saveToDatabase(user){ | ||
console.log(`Guardando el usuario ${user.nombre} en la base de datos`); | ||
} | ||
} | ||
|
||
// Uso de Ejemplo Correcto | ||
const user = new User_Correcto('Antonio', '[email protected]'); | ||
console.log(user.getUserData()); | ||
|
||
const userRepository = new UserRepository(); | ||
userRepository.saveToDatabase(user); | ||
|
||
|
||
|
||
/**-----DIFICULTAD EXTRA-----*/ | ||
|
||
// Pendiente | ||
|
||
/**-----DIFICULTAD EXTRA-----*/ |