๐ WAYPOINT LESSON
Checkpoint โ Classes
โญ beginnerโณ 20 min read๐ Lesson 37 of 85
A bank account: an owner, a balance, and two doors โ every mutation validated, every invariant testable.
Checkpoint: the bank account
Task: implement nested class Solution.BankAccount:
- Constructor
(string owner, decimal openingBalance)โ throwsArgumentExceptionfor a null/whitespace owner or a negative opening balance. - Read-only
OwnerandBalanceproperties. Deposit(decimal amount)โ throwsArgumentExceptionunlessamount > 0; otherwise adds to the balance.Withdraw(decimal amount)โ throwsArgumentExceptionunlessamount > 0, throwsInvalidOperationExceptionwhen funds are insufficient; otherwise subtracts.
The invariant: the balance only ever changes through positive, funded operations. A rejected operation must leave the balance exactly as it was.