File tree 1 file changed +16
-21
lines changed
Roadmap/29 - SOLID ISP/javascript
1 file changed +16
-21
lines changed Original file line number Diff line number Diff line change @@ -114,46 +114,41 @@ fish.eat(); // Neo the Dolphin is eating
114
114
115
115
// Extra
116
116
117
- class BlackAndWhitePrint {
117
+ class Printer {
118
118
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." )
121
121
}
122
122
if ( ! this . print ) {
123
123
throw new Error ( "Debes implementar el método print" )
124
124
}
125
125
}
126
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
- }
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." )
135
137
}
136
138
}
139
+
137
140
const sendingFax = {
138
141
sendFax ( ) {
139
142
console . log ( "Enviando fax." )
140
143
}
141
144
}
145
+
142
146
const scanner = {
143
147
scanning ( ) {
144
148
console . log ( "Escaneando documento." )
145
149
}
146
150
}
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
+
157
152
Object . assign ( ColorPrinter . prototype , sendingFax )
158
153
Object . assign ( ColorPrinter . prototype , scanner )
159
154
You can’t perform that action at this time.
0 commit comments