Subtypes must be substitutable for their base type without breaking behavior.
// dirty — Square breaks Rectangle's contract
class Rectangle {
setWidth(w) { this.width = w; }
setHeight(h) { this.height = h; }
area() { return this.width * this.height; }
}
class Square extends Rectangle {
setWidth(w) { this.width = w; this.height = w; } // breaks LSP!
setHeight(h) { this.width = h; this.height = h; }
}Refactor using factory functions so createRectangle and createSquare are independent — no inheritance. Both expose area().
solve('square', 5) → 25 (side² )solve('rect', 4, 6) → 24 (width × height)
Sample tests