Hi,
Can anybody tell me what the difference between Encapsulation and Abstraction?
I have read many articles on it but don't make much sense to me. Please give me real life example not just the theory.
Thanks a lot in advance.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sujeet SumanPosted Oct 20, 2015, 2:44 AM
Pooja SharmaPosted Nov 15, 2010, 9:00 AM
Do you mean abstraction is for outside the world and encapsulation is for the developers itself?
I mean, developer breaks down the big problem into multiple methods with the help of design pattern or architecture. This is called encapsulation.
Through Abstraction we just show essential feature or method to the user of our class and hide the implementation.
Prasant JinagaPosted Nov 14, 2010, 11:56 PM
Abstraction is the external hiding of that complexity. This is largely accomplished through hiding internal methods and only exposing the minimum set of tools the user needs to accomplish the task.
Like when you drive a car, you know what the gas pedal does but you may not know the process behind it because it is encapsulated.
Let me give an example in C#. Suppose you have an integer:
int Number = 5;
string aStrNumber = Number.ToString();
you can use a method like Number.ToString() which returns you characters representation of the number 5, and stores that in a string object. The method tells you what it does instead of how it does it.
encapsulation puts some things in a box and gives you a peephole; this keeps you from mucking with the gears.
abstraction flat-out ignores the details that don't matter, like whether the things have gears, ratchets, flywheels, or nuclear cores; they just "go"