Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cypress/integration/solid2/ejemplo1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ProductosEnAlacena {
productos = ["Piña", "Manzanas", "Harina"];
existeProducto(producto) {
// indexOf nos devuelve la posición del producto en el array,
// si la posición es -1 significa que no existe el producto
return this.productos.indexOf(producto) !== -1;
}
}

11 changes: 11 additions & 0 deletions cypress/integration/solid2/ejemplo2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ProductosEnAlacena {
productos = ["Piña", "Manzanas", "Harina"];
existeProducto(producto) {
// indexOf nos devuelve la posición del producto en el array,
// si la posición es -1 significa que no existe el producto
return this.productos.indexOf(producto) !== -1;
}
agregarProducto(producto) {
this.productos.push(producto);
}
}
28 changes: 28 additions & 0 deletions cypress/integration/solid2/herencia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Person{
//static sCount=0 //1
constructor(name){
this.name=name;
this.sCount++;
}
// Método de instancia // 2
getName(){
console.log(this.name);
}
static sTest(){
console.log("static method test");
}
}

class Man extends Person{
constructor(name){
super(name);
this.sex="male";
}
}
var man=new Man("David");
man.getName();
//man.sTest()
Man.sTest();



32 changes: 32 additions & 0 deletions cypress/integration/solid2/pdf1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// O : Open/Closed Principle
// Clases abiertas para ser extendidas, pero cerradas para ser modificadas
// Ejemplo 1:

class Pdf {
constructor(name, size) {
this.name = name;
this.size = size;
}

// ...
}
class Png {
constructor(name) {
this.name = name;
}

// ...
}
class Printer {
function printFile(file) {
if (file instanceof Pdf) {
// Print Pdf...
} else if (file instanceof Png) {
// Print Png...
}
}
}




42 changes: 42 additions & 0 deletions cypress/integration/solid2/pdf2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// O : Open/Closed Principle
// Clases abiertas para ser extendidas, pero cerradas para ser modificadas
// Ejemplo 1:

class Printable {
function print() {
// ...
}
}

class Pdf extends Printable {
constructor(name, size) {
super();
this.name = name;
this.size = size;
}

// Override
function print() {
// ...
}
}

class Png extends Printable {
constructor(name) {
super();
this.name = name;
}

// Override
function print() {
// ...
}
}

class Printer {
function printFile(file) {
file.print();
}
}


71 changes: 71 additions & 0 deletions cypress/integration/solid2/pokemon1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class Pokemon {
#name = "";
#type = ""

constructor(name, type) {
this.#name = name;
this.#type = type;
}

get name() {
return this.#name;
}

get type() {
return this.#type;
}

}

/*
Se genera una clase para procesar los ataques de
los pokemons dependiento del tipo de este.
*/
class ProcessAttack {
/*
Se crea método que permite procesar los ataques
de un listado de pokemons.
*/
allPokemonAttack(pokemonList) {
const ATTACKS = pokemonList.reduce((output, pokemon) => {
let attack = "";
const { name, type } = pokemon;
/*
Se crea un listado de casos que permite asignar
un ataque dependiendo el tipo de pokemon.
*/
switch(type) {
case "Electric":
attack = "Impactrueno ⚡️";
break;
case "Fire":
attack = "Aliento igneo 🔥";
break;
case "Water":
attack = "Pitsola de agua 🔫";
break;
attack = "Ataque base";
default:
}
return `${output}${name}, ${attack}\n`;
}, "");
return ATTACKS;
}
}
// Se crean instancias de la clase pokemon
const flareon = new Pokemon("Flareon", "Fire");
const jolteon = new Pokemon("Jolteon", "Electric");
const vaporeon = new Pokemon("Vaporeon", "Water");

// Creamos una instancia de la clase ProcessAttack
const Attack = new ProcessAttack()
// invocamos al método allPokemonAttack y enviamos las
// instancia de la clase pokemon
const MSG = Attack.allPokemonAttack([flareon, jolteon, vaporeon]);
console.log(MSG);
/*
Salida
Flareon, Aliento igneo 🔥
Jolteon, Impactrueno ⚡️
Vaporeon, Pitsola de agua 🔫
*/
119 changes: 119 additions & 0 deletions cypress/integration/solid2/pokemon2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
class Pokemon {
#name = "";
#type = ""

constructor(name, type) {
this.#name = name;
this.#type = type;
}

get name() {
return this.#name;
}

get type() {
return this.#type;
}

/*
Cargamos el metodo attack para que todas
las clases que hereden de pokemon puedan utilizarlo
*/
get attack() {
const { name } = this;
return `${name}, Ataque base`;
}

}

/*
Por cada tipo de pokemon crearemos una nueva clase
la cual heredara de la clase pokemon
*/
class TypeElectric extends Pokemon {
constructor(name) {
/*
Invocamos el constructor de la clase pokemon
y pasamos por defecto el tipo Electric
*/
super(name, "Electric");
}

get attack() {
const { name } = this;
return `${name}, Impactrueno ⚡️`;
}
}

class TypeFire extends Pokemon {
constructor(name) {
/*
Invocamos el constructor de la clase pokemon
y pasamos por defecto el tipo Fire
*/
super(name, "Fire");
}

get attack() {
const { name } = this;
return `${name}, Aliento igneo 🔥`;
}
}

class TypeWater extends Pokemon {
constructor(name) {
/*
Invocamos el constructor de la clase pokemon
y pasamos por defecto el tipo Water
*/
super(name, "Water");
}

get attack() {
const { name } = this;
return `${name}, Pitsola de agua 🔫`;
}
}

/*
Se genera una clase para procesar los ataques de
los pokemons dependiento del tipo de este.
*/
class ProcessAttack {
/*
Se crea método que permite procesar los ataques
de un listado de pokemons.
*/
allPokemonAttack(pokemonList) {
/*
En este caso solo basta con recibir el listado de pokemons
para porder ejecutar un ataque, ya que cada elemento del listado
cuenta con su propio ataque.
*/
const ATTACKS = pokemonList.reduce((output, pokemon) => {
let msg = "";
const { attack } = pokemon;
return `${output}${attack}\n`;
}, "");
return ATTACKS;
}
}

// Creamos una instancia de la clase ProcessAttack
const Attack = new ProcessAttack()

// invocamos al método allPokemonAttack y enviamos las
// instancia te cada tipo de pokemon
const MSG = Attack.allPokemonAttack([
new TypeFire("Flareon"),
new TypeElectric("Jolteon"),
new TypeWater("Vaporeon"),
new TypeElectric("Pikachu")
]);
console.log(MSG);
/*
Salida
Flareon, Aliento igneo 🔥
Jolteon, Impactrueno ⚡️
Vaporeon, Pitsola de agua 🔫
*/