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.