DELAPARRA
Index
Color
NL
Category: Programming paradigms

Encapsulation

Explained by Updated

What is Encapsulation?

Encapsulation: Hiding internal data and only exposing a clean public interface. The engine of a car is hidden — you only interact with the steering wheel and pedals. Encapsulation means hiding an object's internal details and only exposing what others need. You use a car through the steering wheel and pedals; the engine is under the bonnet.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Encapsulation

How is Encapsulation used in practice?

In code, an Order class might keep its lines private and offer addLine() and total(). Other code cannot put the order in an invalid state, because every change goes through methods that check the rules.

What should you keep in mind with Encapsulation?

The benefit is freedom to change the inside without breaking the outside. You can switch how totals are calculated or stored, and code that calls total() keeps working. Keep properties private by default and expose behaviour rather than raw data. A class with public setters for everything has no real boundary, and its rules end up scattered across the codebase.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with E

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.