Skip to content

Commit f86c7a0

Browse files
committed
#29 - Javascript
1 parent 71973f2 commit f86c7a0

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

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

+51-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,54 @@ console.log('\n');
110110

111111
const fish = new Fish('Neo the Dolphin');
112112
fish.swim(); // Neo the Dolphin is swimming
113-
fish.eat(); // Neo the Dolphin is eating
113+
fish.eat(); // Neo the Dolphin is eating
114+
115+
// Extra
116+
117+
class BlackAndWhitePrint {
118+
constructor() {
119+
if (new.target === BlackAndWhitePrint) {
120+
throw new Error("BlackAndWhitePrint es una interface no puedes instanciarla.")
121+
}
122+
if (!this.print) {
123+
throw new Error("Debes implementar el método print")
124+
}
125+
}
126+
}
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+
}
135+
}
136+
}
137+
const sendingFax = {
138+
sendFax() {
139+
console.log("Enviando fax.")
140+
}
141+
}
142+
const scanner = {
143+
scanning() {
144+
console.log("Escaneando documento.")
145+
}
146+
}
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+
}
157+
Object.assign(ColorPrinter.prototype, sendingFax)
158+
Object.assign(ColorPrinter.prototype, scanner)
159+
160+
const multifuncional = new ColorPrinter()
161+
multifuncional.print()
162+
multifuncional.sendFax()
163+
multifuncional.scanning()

0 commit comments

Comments
 (0)