class BankAccount invariant: balance >= 0 โœ“
๐Ÿ”’ private ยท shielded
this.#balance
$100
// only this object's own methods can reach in
โœ— direct access
Reach in from outside: account.balance = X. The field is private โ€” this is blocked.
โœ“ through methods
Go through the front door. The method validates, then updates the shielded field.
console
โ–ธ The left column bounces off the shield โ€” outside code can't touch a private field. The right column runs validation first, so the balance >= 0 invariant always holds.