When building applications, we often need to add new features or change behavior. A common mistake is modifying existing code every time we need something new. This can easily introduce bugs and break parts of the system that were already working. The Open-Closed Principle (OCP) helps solve this problem. What is Open-Closed Principle? The idea is simple: Software entities should be open for extension, but closed for modification. That means: You should be able to add new behavior Without changing existing code Why This Matters When we modify existing code: We risk breaking existing functionality Testing becomes harder The code becomes less stable over time Instead, we should extend the code in a safe way. Bad Example (Modifying Existing Code) Let’s say we have a class that calculates discounts: class DiscountService { calculate(price, type) { if (type === "regular") { return price * 0.1; } els...