Encapsulation
Domain: Design Principles
π― Motivation
Encapsulation hides internal state and requires all interaction through methods. This protects data from unexpected changes and makes behavior easier to evolve safely.
π Concrete Example
A BankAccount class stores balance privately and exposes deposit(amount) and withdraw(amount) methods. No outside code can set balance directly, preventing errors.
π Analogy
A vending machine hides its wiring behind buttons. You press βcolaβ and get a drink; you never touch the gears, so you cannot break the mechanism.