You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//#28 - Principio SOLID de Sustitución de Liskov (Liskov Substitution Principle, LSP)
2
+
/*
3
+
* EJERCICIO:
4
+
* Explora el "Principio SOLID de Sustitución de Liskov (Liskov Substitution Principle, LSP)"
5
+
* y crea un ejemplo simple donde se muestre su funcionamiento
6
+
* de forma correcta e incorrecta.
7
+
*
8
+
* DIFICULTAD EXTRA (opcional):
9
+
* Crea una jerarquía de vehículos. Todos ellos deben poder acelerar y frenar, así como
10
+
* cumplir el LSP.
11
+
* Instrucciones:
12
+
* 1. Crea la clase Vehículo.
13
+
* 2. Añade tres subclases de Vehículo.
14
+
* 3. Implementa las operaciones "acelerar" y "frenar" como corresponda.
15
+
* 4. Desarrolla un código que compruebe que se cumple el LSP.
16
+
*/
17
+
18
+
/* The Liskov Substitution Principle (LSP) is one of the five SOLID principles of object-oriented programming. This principle states that objects of a derived class should be able to replace objects of the base class without altering the correctness of the program. */
19
+
20
+
letlog=console.log;
21
+
22
+
window.addEventListener('load',()=>{
23
+
constbody=document.querySelector('body');
24
+
consttitle=document.createElement('h1');
25
+
26
+
body.style.setProperty('background','#000');
27
+
body.style.setProperty('text-align','center');
28
+
29
+
title.textContent='Retosparaprogramadores #28.';
30
+
title.style.setProperty('font-size','3.5vmax');
31
+
title.style.setProperty('color','#fff');
32
+
title.style.setProperty('line-height','100vh');
33
+
34
+
body.appendChild(title);
35
+
36
+
setTimeout(()=>{
37
+
alert('Retosparaprogramadores #28. Please open the Browser Developer Tools.');
38
+
},2000);
39
+
log('Retosparaprogramadores #28');
40
+
});
41
+
42
+
43
+
classShape{
44
+
area(){
45
+
thrownewError("Method 'area' must be implemented");
0 commit comments