A coupon function reopened for every coupon
transcript
Marketing wants a new coupon. You open the same function. Again.
First, flat 50 off. An if. Then 20 percent off. An else-if. Then a capped first-order coupon. Another one. And a festive coupon. The same function, opened four times.
Every coupon reopens code that already works. A typo in the new branch can break an old coupon. A new coupon should be new code, and nothing else should move.
Put the discount behind one interface. Each coupon is one small class. The fifth coupon is a new class and one registry line. The apply function stays untouched.
But here's the catch. No code is closed against everything. A coupon that needs order history changes the interface. Every coupon edited.
Four edits is evidence. Close against the variation you have seen. And the registry line is a real edit. It lands in the wiring, not the logic.
Full breakdown in the lecture.