# Open/Closed Principle

Add new behavior by adding code, not by changing code that already works.

## What is **Open/Closed Principle**?

The **Open/Closed Principle** says code should be open for extension but closed for modification: you add new behavior by adding new classes, not by editing working ones.

```csharp
public interface IDiscount { decimal Apply(decimal price); }

// New discount? Add a class; the checkout code stays untouched.
public class StudentDiscount : IDiscount
{
    public decimal Apply(decimal price) => price * 0.9m;
}
```

Level: Freelancer · [More OOP terms at this level](https://www.ask-codey.com/glossary/subjects/oop/freelancer)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/open-closed-principle
