Open/Closed Principle — a practical guide to OCP SOLID with clear examples you can reuse in real projects.
OOP Tutorial Series (48/65). Prefer one article? Read the complete OOP tutorial.
Short description
Add new behavior via new classes implementing interfaces, instead of editing giant switch statements repeatedly.
OCP sketch
interface Discount { public function apply(float $total): float; }
class PercentageDiscount implements Discount {
public function __construct(private float $percent) {}
public function apply(float $total): float { return $total * (1 - $this->percent / 100); }
}