Last active
September 2, 2020 04:06
-
-
Save konami12/3039456df210421462f07934cdd269bd to your computer and use it in GitHub Desktop.
✅ Principio de Responsabilidad Única
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 Pokemon { | |
#name = ""; | |
#type = "" | |
#evolutions = []; | |
constructor(name, type, evolutions) { | |
this.#name = name; | |
this.#type = type; | |
this.#evolutions = evolutions; | |
} | |
get name() { | |
return this.#name; | |
} | |
get type() { | |
return this.#type; | |
} | |
get evolutions() { | |
return this.#evolutions; | |
} | |
} | |
/* | |
para aplicar el principio de responsabilidad única | |
separamos todas las operaciones que tengan que ver | |
con acciones dentro de la base de datos. | |
*/ | |
class DataBase { | |
// Método principal | |
constructor(pokemon) {} | |
saveData() { ... } | |
findData() { ... } | |
updateData() { ... } | |
deleteData(){ ... } | |
} | |
// Creamos la instacia de la clase pokemon | |
const Eevee = new Pokemon("Eevee", "normal", ["Jolteon", "Vaporeon", "Flareon"]); | |
// pasamos los la instancia del pokemon | |
const DB = new DataBase(Eevee); | |
// creamos un nuevo registro | |
DB.saveDateDB(Eevee); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment