Your wallet balance says minus 300 rupees
transcript
Your wallet says minus 300 rupees. You had 500. You paid 800. The app said yes.
You top up 500. The balance is 500. Dinner is 800. The code just subtracts. Minus 300. No error. No check. The wallet never said no, because it couldn't.
The balance is one public field. Checkout, refunds and support can all set it. Every caller must remember the rule. Checkout. Refunds. The support tool. One of them forgets. The balance is corrupted, and nobody can tell which line did it.
But here's the catch. Adding a check to every caller won't fix it. So where does the rule live?
Make the balance private. Only deposit and withdraw can change it. Withdraw checks first. Need 800, have 500: refused. The balance stays 500. Now nobody can forget the check.
A rule that must always hold belongs to the object it protects. Write it once, in the wallet. Every caller is safe.
Full breakdown in the lecture.