← Object-Oriented Programming learning pathObject-Oriented Programming · Module 3 of 10
Encapsulation
Hide internal data and expose controlled access.
📖 Key ideas
- Encapsulation bundles data and methods and restricts direct access.
- Access modifiers: private, protected, public.
- Getters and setters control reading and writing.
- Validation happens inside setters.
- 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