SOLID Principles in JavaScript
Which SOLID principle suggests that software entities should be open for extension but closed for modification?
// Before:
class Rectangle {
constructor(width, height) {
this.width = width;
this.height = height;
}
area() {
return this.width * this.height;
}
}
// After:
class Shape {
area() {}
}
class Rectangle extends Shape {
constructor(width, height) {
super();
this.width = width;
this.height = height;
}
area() {
return this.width * this.height;
}
}