Encapsulation
- •
What it is
- •
restricting direct access to an object's internal data, exposing it only through defined public methods, to protect data integrity
- •
- •
- •
Example
- •
a
Mahasiswaclass keeps itsnamafield private, exposing it only viagetNama()/setNama()rather than allowing direct field access
- •
- •
Distinguish from
- •
Unavailable reference — abstraction hides unnecessary complexity (what something does, not how); encapsulation restricts access to data, regardless of complexity
- •
- •
- •