Lesson 8: Information hiding — the _x convention
In lesson 6 anyone could write acc.balance = -999 and break the account. Today we learn the principle that prevents it: encapsulation — internal data is marked with an underscore, and the outside world goes through methods.
A restaurant's back room: customers order through the waiter (methods) and don't walk into the kitchen (_balance) to cook for themselves.
- encapsulation
- Bundling data and actions in one class, and hiding the internal details behind methods.
- underscore convention
- A name starting with _ (like _balance) signals: internal to the class — don't touch from outside.