I'll Be Backend
Principles

Open/Closed Principle: Add Rules Without Editing Old Code

The Open/Closed Principle says code should be open for extension and closed for modification: you add new behavior by adding new code, and the code that already works stays as it is. These lessons take an expense policy that grows one if block per finance rule, turn each rule into its own class, and let the caller register them, so a new rule is a new class plus one added line.

Pick your language

When to use it

Use it when

New rules arrive often, each one stands alone, and different people add them.

Skip it when

Two rules change once a year. Two if blocks read easier than an interface and a class per rule.

Spot it by

A method that grows one more if block with every feature request.