Click here to Skip to main content
15,178,967 members
Please Sign up or sign in to vote.
3.00/5 (6 votes)
See more:
What is the difference between abstraction,encapsulation,data hiding?Where they implemented in c#.
please explain in terms of general life example and Programming point of view. ?
Monjurul Habib 11-Dec-11 23:08pm
is this the only thing you can do ??..down vote ??

There are a number of excellent answers here, but let me toss in another point of view, if I may. The jargon in this industry is a good example of data hiding, in many cases, and being a simple person of simple mind, perhaps I can simplify.

First, Abstraction is simply separating the top level usefulness of a thing from the details of its implementation. As a user of a control, you really don't care how the control does its job, what kernel operations it invokes, what interrupts it might raise. You only care what methods it has for you to call, and what results to expect of them. That's abstraction at work; keeping the details away from the consumer of the object, so that the programmer is freed from worrying about details that aren't relevant to his assignment.

Second, Encapsulation is simply combining the data members and functions into a single entity called an object. This may seem trivial to you, but when it was first proposed it was very hard to grasp. In the early days we had, within a program, a data region and a code region, dedicated at compile time. The concept of objects, which were self-contained entities comprised of their own functions and data items was really hard to embrace, but ultimately it was very useful to understand and adopt. When combined with the concept of abstraction, this gave us the opportunity to write truly reusable code. So long as we didn't change the methods and data members exposed to users, we could modify the internal implementations of our objects as much as we wanted to, without breaking any applications which depended on them.

Lastly, Data Hiding has to do with restricting access to internal variables used by an object to perform its magic. Originally, data hiding was proposed to protect these internal data items from being modified by users of an object. The Private access modifier was introduced to provide that protection. The concept has evolved to embrace protection of all object data members from outside manipulation, by introducing the concept of Properties (in C#, at least). As a rule, member data items are not accessible outside of the class which defines them. The programmer must explicitly define a get or set method to allow another object to read or modify these values.

Although many programmers today take these concepts for granted, they were world shaking ideas when they first appeared, and very difficult to grasp. I can recall when Turbo Pascal 5.5 was released, and that was my first introduction to OOP and these fundamental concepts. It shattered everything I knew about programming, and forced me into a whole new way of thinking about software. I wonder what the next great paradigm shift will bring? You'll probably be around to see it, but I might not, thankfully...
sanjy1 11-Dec-11 23:34pm
this is awsome.
i must appreciate you.
Atul Khanduri 5-Dec-13 15:22pm
Very nice explanation....:)
My 5....
awaisdar 11-Dec-11 23:35pm
nicely explained.

do hit back with your answers
Abhinav S 12-Dec-11 0:45am
Very well answered. 5.
R.SIVAA 18-Jul-12 4:08am
Encapsulation and Data Hiding explanation and history given was really excellent.
Member 10476040 12-May-14 4:42am
Hi Roger,
Your explanation is nice. But, saying "Encapsulation is simply combining the data members and functions into a single entity called an object" is wrong it must be class not an object. Object is created from class!!!
Roger Wright 12-May-14 11:38am
Incorrect. The encapsulation occurs in the object; the class merely defines how to build the object.
Member 10476040 13-May-14 2:39am
OK. But please can you explain "the class merely defines how to build the object."
Kunal Pandhare 20-Aug-14 5:15am
Very nicely explained Roger. these are bit confusing when asked by interviewer :) most of the time I almost ended up in confusing state before interviewer. Thanks to you, Now my idea are clear and I can explore and make it FIX in my mind. :)
Member 10584881 13-Sep-14 23:22pm
This is awesome... the way you explained these concepts is awesome!
Bhausaheb Gurav 13-Sep-14 23:32pm
This is awesome... I must say!
Arasappan 5-Sep-15 5:40am
girishmeena 14-Sep-15 16:16pm
Simply 5, Thanks
girishmeena 28-Aug-16 5:10am
There are contradict answers on internet for this question. please refer

I am still not sure which one is correct one. Thanks
Abhinav S 11-Dec-11 10:16am
5. Of course.
Monjurul Habib 11-Dec-11 10:17am
thank you
RaviRanjanKr 11-Dec-11 10:28am
My 5!
Monjurul Habib 11-Dec-11 10:30am
thank you
awaisdar 11-Dec-11 10:32am
chek out the correct answer.
i have posted it
Wonde Tadesse 11-Dec-11 13:16pm
Monjurul Habib 11-Dec-11 20:27pm
thank you Wonde
Sergey Alexandrovich Kryukov 11-Dec-11 22:14pm
So far, this is the only reasonable response, my 5. All other answers may present a pretty good effort, but they are fool of different amount of absurdities.

Main thing to point out is the incorrectness of this question.

I also added my answer, please see -- you might find it interesting, I hope.
Monjurul Habib 11-Dec-11 22:17pm
thank you
Difference?! How about using some logic when formulating questions?

Not clear? Well, read my recent answer to some other question what is the difference between the class and encapsulation in programming[^]; it it fully applicable to your, see also all the comments in the discussion.

Also, you really need to have an idea on how to ask good questions, see this discussion: How to ask a good question?[^].

In my opinion, so far the most adequate advice is the one by Monjurul Habib. Try to use it well. I would also add:[^],[^].

As to abstraction, it's a philosophical category which you should be familiar first. In programming, this is… all you do in programming. When you create a method, this is abstraction, because you abstract out of the idea of doing some code here and not and allow to call it from many places. When you add a method parameter, you abstract the method out of the hard-coded value. Every type is abstraction, etc.

So, this comes first:[^], and then this:[^], and this:[^].

awaisdar 11-Dec-11 22:20pm
thanks for your answer.
you kind of explaind the remaining concept very well that was abstraction.

i am really sorry to tell you dear, that we can find whole lot of wikipedia links when we google it.
and its sure when we are posting some question right here it means we didnt find the souteable answer from the web.
and we need some one who tell us like in common language , genral expamples.

butt its sad here sometimes we also get weblinks

i feel sorry for this.
but thank you for posting ABSTRACTION.
Monjurul Habib 11-Dec-11 22:23pm
web links because those are written with much time and effort. did you ever write any article?? do you know how much effort does it cost?
Sergey Alexandrovich Kryukov 11-Dec-11 22:40pm
You are welcome.
But is this a reason for voting 1?

As to your expectations, reading articles, finding real-life samples and using brain -- please see other comments below -- you might find them interesting.

I wish you more of more correct questions, hard work, good education and all kinds of success,
Monjurul Habib 11-Dec-11 22:21pm
perfect answer,5++, some people never want to read any article, how come they always expect spoon feeding.
Sergey Alexandrovich Kryukov 11-Dec-11 22:34pm
Exactly, this is the real problem. By the way, one can actually find enough real-time examples, but to recognize that they are relevant to the topic, one needs to... read articles. Infinite loop? Not really, this loop is exited by some hard work and using one's brain.

Thank you, Monjurul.
Sergey Alexandrovich Kryukov 11-Dec-11 22:41pm
And by the way, look at some more comments. You always come across the lovers of spoon feeding. :-)
sanjy1 11-Dec-11 22:33pm
some times we expact someone tell us in their own language not that bookish language.
ofucrse we read articles he should be aware of.
Sergey Alexandrovich Kryukov 11-Dec-11 22:37pm
Who "we"? Why not imposing more requirements to ourselves instead of just "expecting"? (And voting 1s for good friendly solutions? :-)
Those who afraid of "bookish language" lack culture; but they really need it? How to acquire some culture? Hard work, reading books and less complains.

How about that?
awaisdar 11-Dec-11 22:40pm
hey stop guys.
this was simple question thought it could help many.
but this not right to fight
Sergey Alexandrovich Kryukov 11-Dec-11 22:45pm
OK, I think case closed. But you are the one who sparked fight, admit it. And, this is not a fight, because there are no equal partners here to fight, in particular, I cannot consider you as an opponent, sorry to point it out. Please either follow my advice or not, ask a follow up questions, etc.

I would better suggest you accept this solution formally (green button).
sanjy1 11-Dec-11 22:42pm
haha if you are here for bookish language than you shouldnt be here.
try to learn what does that word means?
Sergey Alexandrovich Kryukov 11-Dec-11 22:47pm
Please be so kind to let me decide where to be. Be a bit considerate.

Case closed, I hope.
Abhinav S 12-Dec-11 0:45am
5 of course.
Thank you, Abhinav.
girishmeena 28-Aug-16 6:08am
I wish all other answers of this question get deleted from internet and only this answer can stay, to avoid all the confusion around this question. or all people can have this answer in their head while reading other's answer so that they can differentiate easily.
I also recommend to read different flavor of encapsulation (A language mechanism for restricting direct access to some of the object's components, A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data ) and
abstraction (control abstraction, data abstraction and abstraction principal) which are given in above wiki link to get clear picture.
Thanks again
In a nutshell, Encapsulation is hiding certain parts of your program so that they are not accessible to everyone.
Abstraction is hiding the complexity of the program.
This[^] might help you out.
Monjurul Habib 11-Dec-11 10:16am
Abhinav S 11-Dec-11 12:08pm
Thank you.
RaviRanjanKr 11-Dec-11 10:28am
My 5!
Abhinav S 11-Dec-11 12:08pm
Thanks Ravi.
Wonde Tadesse 11-Dec-11 13:16pm
Abhinav S 11-Dec-11 13:20pm
Thank you Wonde.

means grouping up of related members (variables and functions) into a single unit called class.


In our everyday lives, most of us use a video recorder via either the controls on the front of it or via a remote control. We all know which buttons to press in order to watch a program or record a program, this is done via the interface we have with the video recorder. The manufacturer can change the internal workings of the hardware, but this would not often affect us as a user because the interface we have would be the same. That is a play button, a record button, fast forward, rewind, stop, pause, etc.

Coding Encapsulation

The following code demonstrates a class containing some data and a method that acts upon the data (without data hiding):

class Counter
  public int Count;
  public Counter()
    Count = 0;
  public void incCount()

Although the member variable can be directly accessed, the data and its method is encapsulated in a class.


Data hiding is linked to encapsulation; however data hiding is not encapsulation as it is sometimes described in this way.

Data hiding is simply the means to remove direct access to an object’s information, by providing operations that perform actions on the data. This way any changes to the value of the data must come through the interface to the data, which is an operation. Thus we use access operations or properties.

An Example

In our person object, access to the data forename is supplied through the access operations set forename() and get forename().
Coding Data Hiding

The following code demonstrates a class containing some data that is hidden:

class Counter
  private int Count;
  public Counter()
    Count = 0;
  public void setCount( int newVal )
    Count = newVal;
  public int getCount()
    return Count;

This piece of code is also encapsulated, showing that you can have encapsulation without data hiding, but you cannot have data hiding without encapsulation.


As to abstraction, it's a philosophical category which you should be familiar first. In programming, this is… all you do in programming. When you create a method, this is abstraction, because you abstract out of the idea of doing some code here and not and allow to call it from many places. When you add a method parameter, you abstract the method out of the hard-coded value. Every type is abstraction, etc.
sanjy1 11-Dec-11 23:40pm
:) Cheers
awaisdar 13-Dec-11 10:53am
Member 9667113 16-Jan-13 12:43pm
sm one pls tell me the exact diff b/w all above three concepts of oops
In addition to above answers. I will suggest you to view the given practical video.
What is the difference between Abstraction and Encapsulation[^]
Monjurul Habib 11-Dec-11 20:28pm
nice link 5!
RaviRanjanKr 12-Dec-11 2:38am
Thanks :)
Data Hiding And Abstraction is same thing, And encapsulation is process to keep object's property and method with each other After encapsulation object is also abstract
awaisdar 11-Dec-11 10:22am
listen i have read much aobut it. give some real world example and one prgramming
Encapsulation is the ability to bundle related data and functionality within a single, autonomous entity called a class.

Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation.

Abstraction – (show only the necessary details to the client of the object.)
The concept of abstraction relates to the idea of hiding data that are not needed for presentation. The main idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details. This separation is achieved in order that the properties of the abstract data type are visible to the user interface and the implementation details are hidden.

An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.

Data hiding is manifested by enabling programmers to restrict access to certain data and code. This way, a class may prevent other classes and functions from accessing its data members and some of its member functions, while allowing them to access its non-restricted members.

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