← Object-Oriented Programming learning path
Object-Oriented Programming · Module 3 of 10

Encapsulation

Hide internal data and expose controlled access.

📖 Key ideas

  1. Encapsulation bundles data and methods and restricts direct access.
  2. Access modifiers: private, protected, public.
  3. Getters and setters control reading and writing.
  4. Validation happens inside setters.
  5. Python uses conventions (_name, __name).
💡 Real-life example: Encapsulation is an ATM: you get cash through buttons, never by opening the vault.
EncapsulationHiding internal state
privateAccessible only inside the class
Getter/setterControlled access methods
Data hidingPreventing direct field access