Skip to content

Commit 5cf6ed0

Browse files
committed
#29 - Javascript
1 parent f86c7a0 commit 5cf6ed0

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

Roadmap/29 - SOLID ISP/javascript/parababire.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -114,46 +114,41 @@ fish.eat(); // Neo the Dolphin is eating
114114

115115
// Extra
116116

117-
class BlackAndWhitePrint {
117+
class Printer {
118118
constructor() {
119-
if (new.target === BlackAndWhitePrint) {
120-
throw new Error("BlackAndWhitePrint es una interface no puedes instanciarla.")
119+
if (new.target === Printer) {
120+
throw new Error("Printer es una interface no puedes instanciarla.")
121121
}
122122
if (!this.print) {
123123
throw new Error("Debes implementar el método print")
124124
}
125125
}
126126
}
127-
class ColorPrint {
128-
constructor() {
129-
if (new.target === ColorPrint) {
130-
throw new Error("ColorPrint es una interface no puedes instanciarla.")
131-
}
132-
if (!this.print) {
133-
throw new Error("Debes implementar el método print")
134-
}
127+
128+
class BlackAndWhitePrinter extends Printer {
129+
print() {
130+
console.log("Se imprime en blanco y negro.")
131+
}
132+
}
133+
134+
class ColorPrinter extends Printer {
135+
print() {
136+
console.log("Se imprime a color.")
135137
}
136138
}
139+
137140
const sendingFax = {
138141
sendFax() {
139142
console.log("Enviando fax.")
140143
}
141144
}
145+
142146
const scanner = {
143147
scanning() {
144148
console.log("Escaneando documento.")
145149
}
146150
}
147-
class BlackAndWhitePrinter extends BlackAndWhitePrint {
148-
print() {
149-
console.log("Hace solo impresiones en blanco y negro.")
150-
}
151-
}
152-
class ColorPrinter extends ColorPrint {
153-
print() {
154-
console.log("Hace impresiones a color.")
155-
}
156-
}
151+
157152
Object.assign(ColorPrinter.prototype, sendingFax)
158153
Object.assign(ColorPrinter.prototype, scanner)
159154

0 commit comments

Comments
 (0)