Encapsulation
Encapsulation binds data with its operations, hides internal implementation and exposes only an interface, controlling external access to protect invariants.
Purpose
Information hiding reduces coupling and protects object invariants — a core of object orientation.
Mechanism
Access control: public/private/protected. Private fields are accessible only within the class; public methods provide controlled access. Invariants are maintained at method entry/exit. Java records, C# properties, and Rust pub are encapsulation mechanisms.
Use cases
- Object-oriented design
- Information hiding
- API design