Your delivery fee function grows an if for every rule
transcript
Same dinner. Same restaurant. Your friend pays nothing for delivery. You pay 57 rupees. Why?
Your cart is 240 rupees. The store is 5 point 4 kilometres away. So delivery is 57 rupees. You pay 297. Your friend is a member. Same cart. Delivery is free.
Most people write one function. One branch per rule. Weekend campaign? Another branch. Members? Another one.
Six months later. A rain fee. Festival rates. A rule per city. Every one edits the function that prices every order.
One more branch is one more chance to break the others. So every release retests all of them. Strategy flips it. Each rule is its own class. Old ones never reopen.
The checkout holds one fee policy. It just asks for a fee. Distance and member are two classes behind it. A rain fee? One new class. The checkout never changes.
The rule changes. The job doesn't. So the job becomes the interface. Each rule becomes a class.
Full breakdown in the lecture.