Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Can any one please describe the Abstraction vs Encapsulation with example code.

Thanks
Abhay
Posted

1:
Quote:
Abstraction: In bare terms it means “Understanding”. Better understanding of the system leads to good solution.

Data Abstraction: Data Abstraction (In OOP also known as Object Abstraction) purely talks about the understanding of the Developer about the system that is specific to the given DATA.

So there can be Levels of Abstraction to understand the system which differs from developer to developer. Better systems can be developed with higher levels of abstraction.

Difference: Encapsulation is the deliverables of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs. Abstraction solves the problem in the design side while encapsulation is the implementation.


2:-
Quote:
Encapsulation means we hide the data from directly
interaction and Abstraction means
we bother about what the object can do but don't bother
about how it does?


3:-
Quote:
Encapsulation means we are hiding the code and data in to a
single unit to protect the data from outside world.

Abstraction means we know about the object how it can be
used but we dont know how it is implemented. and we can
hide the data using the AccessSpecifiers.


4:-
Quote:
Data abstraction in OOP is the concept of abstracting the implemetaion to the user. It just gives the functional description but not the implementaion part.
Take an abstract class or an interface for example, it gives the user some method descriptions, but not the internal implementaion.


While Encapsulation in OOP is the process of hiding or securing data from outside functions. The data is strictly binded with function members declared in the same class.
For example in C# we can use properties insde the class to manipulte or access the private data declared in the same class, but cannot do so from outside functions.


5:-
http://maxotek.net/blog/csharp-tutorial-lesson-5-encapsulation-abstraction-t31.html[^]

http://www.c-sharpcorner.com/UploadFile/tusharkantagarwal/objectorientedcsharp11162005070743AM/objectorientedcsharp.aspx[^]
 
Share this answer
 
Comments
Partho Sarathi 6-Sep-17 18:38pm    
Can you change the URL? I've moved the site to a new domain. The old URL does have a 301 Redirect that takes to the same page in the new site. But, I will have to take it down someway down the line. I am talking about URL #1.

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