Abstraction & Encapsulation
The main difference between Encapsulation and Abstraction!¶
Confusion:¶
- Conflicting Behavior like both HIDES!!
Bundling data and methods into a single private unit: This is encapsulation.¶
Concealing the inner workings and exposing only what is necessary: This is abstraction.¶
In the two statements above i didn't used word "HIDE", But if you understand the context and meaning, Then i have used word "HIDE" implicitly in both statement's!!
Encapsulation does involve hiding internal details (e,g Bundling/Hiding/Packing data & methods), its primary purpose is to bundle and protect the data and methods, not necessarily to simplify the interface for the user. Abstraction, however, is all about simplifying the interaction by hiding complexity and showing only the essential parts.
Aspect | Encapsulation | Abstraction |
---|---|---|
Purpose | Protect/bundle data and methods as a single unit | Simplify by exposing only necessary information |
Hides | Internal state, implementation details | Complexity, irrelevant details |