Skip to content

Commit 456df5d

Browse files
#28 - JavaScript
1 parent 02902d2 commit 456df5d

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/** #28 - JavaScript -> Jesus Antonio Escamilla */
2+
3+
/**
4+
* Principio de Segregación de Interfaces: Una clase no debe estar obligada a implementar interfaces que no usa.
5+
* En lugar de tener una interfaz grande y general, se deben tener varias interfaces específicas y pequeñas.
6+
* Este principio establece que los objetos de una clase derivada deben poder ser sustituidos por objetos de la
7+
clase base sin alterar el funcionamiento del programa.
8+
*/
9+
10+
//---EJERCIÓ---
11+
//INCORRECTO
12+
class Bird_{
13+
fly(){
14+
console.log("Flying");
15+
}
16+
}
17+
18+
class Eagle_ extends Bird_{
19+
fly(){
20+
console.log("Eagle flying high!");
21+
}
22+
}
23+
24+
class Penguin_ extends Bird_{
25+
fly(){
26+
throw new Error("Penguins can't fly!!");
27+
}
28+
}
29+
30+
function makeBirdFly_(bird) {
31+
bird.fly();
32+
}
33+
34+
const eagle_ = new Eagle_();
35+
const penguin_ = new Penguin_();
36+
37+
makeBirdFly_(eagle_);
38+
makeBirdFly_(penguin_);
39+
40+
41+
//CORRECTO
42+
class Bird{
43+
move(){
44+
console.log("Moving");
45+
}
46+
}
47+
48+
class FlyingBird extends Bird{
49+
fly(){
50+
console.log("Flying");
51+
}
52+
}
53+
54+
class Eagle extends FlyingBird{
55+
fly(){
56+
console.log("Eagle flying high!!");
57+
}
58+
}
59+
60+
class Penguin extends Bird{
61+
move(){
62+
console.log("Penguin waddling");
63+
}
64+
}
65+
66+
function makeBirdMove(bird) {
67+
bird.move();
68+
}
69+
70+
const eagle = new Eagle();
71+
const penguin = new Penguin();
72+
73+
makeBirdMove(eagle);
74+
makeBirdMove(penguin);
75+
76+
77+
78+
/**-----DIFICULTAD EXTRA-----*/
79+
80+
// Pendiente
81+
82+
/**-----DIFICULTAD EXTRA-----*/

0 commit comments

Comments
 (0)