encapsulation
Installation
SKILL.md
Encapsulation
Overview
Hide internal state. Expose behavior, not data. Control access through methods.
Public fields let anyone modify your object's internals, bypassing validation and breaking invariants. Encapsulation protects data integrity.
When to Use
- Designing classes with state
- Tempted to make fields public
- External code directly modifies object state
- Invariants can be violated by direct access