Ads Here

Monday, August 15, 2011

Difference between Abstraction and Encapsulation








Abstraction
Encapsulation
1. Abstraction solves the problem in the design level.

1. Encapsulation solves the problem in the implementation level.

2. Abstraction is used for hiding the unwanted data and giving relevant data.

2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world.


3. Abstraction lets you focus on what the object does instead of how it does it

3. Encapsulation means hiding the internal details or mechanics of how an object does something.

4. Abstraction- Outer layout, used in terms of design.
For Example:-
 Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.

4. Encapsulation- Inner layout, used in terms of implementation.
For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.




The easier way to understand Abstraction and encapsulation is as follows:-
Real World Example:- 

Take an example of Mobile Phone:- 

You have a Mobile Phone, you can dial a number using keypad buttons. Even you don't know how these are working internally. This is called Abstraction. You have the only information that is needed to dial a number. But not its internal working of mobile.

But how the Mobile Phone internally working?, how keypad buttons are connected with internal circuit? is called Encapsulation.

Summary:

"Encapsulation is accomplished by using Class. - Keeping data and methods that accesses that data into a single unit" 

"Abstraction is accomplished by using Interface. - Just giving the abstract information about what it can do without specifying the back ground details" 

"Information/Data hiding is accomplished by using Modifiers - By keeping the instance variables private or protected."


Related Topics:-

OOPs Concepts
What is Abstraction
What is Encapsulation
What is Inheritance
Polymorphism in .Net
Difference between Abstraction and Encapsulation

17 comments:

KULDEEP said...

nice example :)

Manish Agrahari said...

thanks kuldeep

Manish Agrahari

Shweta Singh said...

Well explained.

Nagesh Kokane said...

Nice artical.. i like real world example..

sameer said...

nice example

ಮನೀಶ್ ಚೌದರಿ said...

great work sir.....now only i understood

Jagdeep Mankotia said...

Very Good and Simple explanation.

Thanks a ton Manish.

Ronnie said...

Thnx Manish. !

Anonymous said...

Thanq for nice explanation. Really helped me

Anonymous said...

can you elaborate the difference
between abstraction and encapsulation with example???

Ravi Teja said...

Thanq for nice explanation. Really helped me Thanks Once Again

Anil Singh said...

Nice explianation..

Om Prakash said...

Good progress Manish Bhai. Congrats..

Hitesh Kumar said...

Real life example of polymorphism

thanks

Ravi Kumar said...

good explonation...

Ravi Kumar said...

good explonation manish sir....

Unknown said...

Thanks manish sharing useful information about data abstraction.I also recommended useful article about data abstraction.

http://www.careerride.com/CSharp-use-of-abstraction.aspx

https://www.mindstick.com/blog/319/abstraction-in-c-sharp-with-example