Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
3.67/5 (4 votes)
See more:
hii friends

i want to know the main diff between abstraction and encapsulation...

Edit: Added the homework tag as this question is a favourite of university lecturers wanting to scare their students
Posted
Updated 23-Jan-11 6:51am
v2
Comments
Sergey Alexandrovich Kryukov 23-Jan-11 11:54am    
Incorrect question.
Everyone should realize that the question in the form "What is the difference between..." can be incorrect and it is most likely incorrect. Examples: "What's the difference between apple and Apple?", "What's the difference between apply and cognitive dissonance?". This question is exactly like the last one.
Sergey Alexandrovich Kryukov 23-Jan-11 11:55am    
Is it interview question? I would not even try to answer...

Abstraction is like going to interviews: you know the general procedure, and that you're going to be asked questions. But you don't know who will ask the questions and what the results will be.

Encapsulation is when an interviewer asks you a question and has the answer in his head, but doesn't give it away: you can't access the answer directly, but you can interact with it by providing an answer and have the interviewer judge whether it matches his expected answer or not.

[edit]just forget it - I only now realized how old that question was .... :-/ [/edit]
 
Share this answer
 
v2
Comments
Emre Ataseven 20-May-14 2:54am    
Good analogy :)
Legor 20-May-14 3:34am    
Why answer a 3 year old question?
Stefan_Lang 20-May-14 3:38am    
As you can see by my edit I didn't realize that at the time of posting. At that time the OP was shown as current in the overview - but only because of the newly posted Solution 9. I didn't bother to check the actual date of the OP...
You might be very surprised to find that you are not the first person to ask this question.

I just googled for difference abstraction encapsulation and I got over 600,000 hits. The first four pages were all people asking this very question, at which point I got bored, so there could have been more.

Have a go for yourself and follow any reference material pointed to by the answerers.

You really should have done this before asking here, you know.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Jan-11 12:21pm    
Reading does seem to be unpopular nowadays!
Compensated! 5+
Did you consider using google, reading your textbooks or asking your teacher for help with your homework ?

Here[^].
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Jan-11 12:21pm    
Reading does seem to be unpopular nowadays!
Compensated! 5+
Encapsulation is hiding implementation details (making a field private for example) and abstraction is using "something" without beeing aware of how it works (when you start the engine of your care you don't care how it works, it just starts, just like when you add a element to a list and you are not thinking how it's implemented).
I hope my English is good enough to make this clear. If not, I can try it again.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Jan-11 12:21pm    
Reading does seem to be unpopular nowadays!
Compensated! 5+
You might want to get a book on OOPS and go through it.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Jan-11 12:21pm    
Reading does seem to be unpopular nowadays!
Compensated! 5+
Abhinav S 14-Oct-13 22:57pm    
Thank you Manfred.
Once you've googled those terms, as CG suggested, you'll still find that things are still a little hazy. It's alright though. One thing a lot of newbie programmers don't get is that unlike coding, which is pretty much an exact science, software design theory is not an exact science. It's like doing a math class for an hour and then attending a class on theoretical long term economics.

I've been programming for 2 decades now, and yet if someone asked me this sort of question my answer would probably not be very interesting, impressive, or enlightening. In fact I suspect I'll promptly flunk the interview!
 
Share this answer
 
Comments
Christian Graus 23-Jan-11 10:54am    
On the other hand I aced an interview in my early days by suggesting that code reuse was a furphy that almost never happens in real life !!!
Nish Nishant 23-Jan-11 10:55am    
LOL. That must have been an interesting job!
Stefan_Lang 20-May-14 2:34am    
Sadly, that does match my experience.
Manfred Rudolf Bihy 23-Jan-11 12:21pm    
Reading does seem to be unpopular nowadays!
Compensated! 5+
Nish Nishant 23-Jan-11 18:19pm    
Thanks.
Abstraction is a concept.
Encapsulation is a tool.
 
Share this answer
 
Comments
fgoldenstein 26-Jan-11 6:26am    
Maybe you use a tool (Visual Studio) to encapsulate a field but encapsulation is a concept. It's hiding implementation details (you make a field private).
Emilio Garavaglia 26-Jan-11 7:43am    
Gee, there is not only a physical and a logical world. There are different level of abstractions. Encapsulation is "(one of) the tool you use to conceptualize an abstraction into an higher abstraction layer". Encapsulation is not only something related to "coding" and programming is not only just "coding".

I was simply tried to synthesize these concept into two rows. They cannot be accurate, but at least a few more mental elasticity from a "professor" is something I have to expect!
To answer this you have to do three things:

- define what abstraction means in OO terms
- define what encapsulation means in OO terms
- compare and contrast the two of them

Encapsulation is a real snake in the grass as most software engineers conflate it with information hiding (another term that's worth looking up for your assignment as it's a form of abstraction) when it's something completely different (it's about bundling, not hiding). However even if you come up with definitions for the terms that aren't quite what your interviewer/examiner wants provided you define them well enough and can cite references for them (in an accademic environment this is particularly important) that shouldn't hinder you getting through.

Cheers,

Ash
 
Share this answer
 
v2
Abstraction is hiding Complexity (Ex:Garbage Collection)
Encapsulation is just a wrapper over Things(Ex:Web Service Contract/Interface)
 
Share this answer
 
Comments
Richard MacCutchan 14-Oct-13 7:11am    
Why are you responding to a question that is nearly three years old? The person who posted this has already graduated or given up on this course.
Abstraction is a thought process of designing an entity by identifying the relevant qualities and behaviors it should have.
- It emphasizes on essential features of an entity rather than its details which means it is more about what the entity will do rather than how it will do.
- It is used when you know something needs to be there but not sure how exactly it should look like.
- It is an earlier step of encapsulation.

Encapsulation is the actual implementation of Abstraction to create the final entity.
- It involves in grouping of data and functionality in a single unit called class.
- It simplifies the functionality by hiding the complexity. It hides the internal details of how an entity does anything and just provide its output.
- It guarantees that the encapsulated data and methods are not accessed by any one outside the encapsulated entity, by using access modifiers.
 
Share this answer
 
v3
Comments
Legor 12-Sep-14 4:10am    
Dont answer posts which are 3 years old
NK Sharma 12-Sep-14 4:43am    
Is there any such policy on CodeProject?? sorry I was not aware of it, I just gave my contribution so that some may got clear idea on the topic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900