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.
just forget it - I only now realized how old that question was .... :-/ [/edit]
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.
Did you consider using google, reading your textbooks or asking your teacher for help with your homework ?
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.
You might want to get a book on OOPS and go through it.
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!
Abstraction is a concept.
Encapsulation is a tool.
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.
Abstraction is hiding Complexity (Ex:Garbage Collection)
Encapsulation is just a wrapper over Things(Ex:Web Service Contract/Interface)
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.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)