Lesson 6: Mini-capstone — BankAccount
Time to connect everything: a class, a constructor, state-changing methods, a guard condition, and __str__. We'll build a real BankAccount class together — just like on the job.
A bank account is the perfect object: it has data (owner, balance) and actions (deposit, withdraw) — and it knows how to say no when there isn't enough money.
- guard condition
- An if check at the start of a method that blocks an invalid action — like overdrawing.
- class design
- Choosing which attributes and methods belong to a class — the data and actions of the thing being modeled.