Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# programming oops
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. ?
Posted 11-Dec-11 5:02am
Comments
Monjurul Habib at 11-Dec-11 23:08pm
   
is this the only thing you can do ??..down vote ??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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...
  Permalink  
Comments
sanjy1 at 11-Dec-11 23:34pm
   
this is awsome.
i must appreciate you.
5!
Atul Khanduri at 5-Dec-13 15:22pm
   
Very nice explanation....:)
My 5....
awaisdar at 11-Dec-11 23:35pm
   
nicely explained.
thanks!
 
do hit back with your answers
Abhinav S at 12-Dec-11 0:45am
   
Very well answered. 5.
R.SIVAA at 18-Jul-12 4:08am
   
Encapsulation and Data Hiding explanation and history given was really excellent.
Member 10476040 at 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 at 12-May-14 11:38am
   
Incorrect. The encapsulation occurs in the object; the class merely defines how to build the object.
Member 10476040 at 13-May-14 2:39am
   
OK. But please can you explain "the class merely defines how to build the object."
Kunal Pandhare at 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 at 13-Sep-14 23:22pm
   
This is awesome... the way you explained these concepts is awesome!
Bhausaheb Gurav at 13-Sep-14 23:32pm
   
This is awesome... I must say!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
v2
Comments
Abhinav S at 11-Dec-11 10:16am
   
5. Of course.
Monjurul Habib at 11-Dec-11 10:17am
   
thank you
RaviRanjankr at 11-Dec-11 10:28am
   
My 5!
Monjurul Habib at 11-Dec-11 10:30am
   
thank you
awaisdar at 11-Dec-11 10:32am
   
chek out the correct answer.
i have posted it
Wonde Tadesse at 11-Dec-11 13:16pm
   
5+
Monjurul Habib at 11-Dec-11 20:27pm
   
thank you Wonde
SAKryukov at 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.
--SA
Monjurul Habib at 11-Dec-11 22:17pm
   
thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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:
 
http://en.wikipedia.org/wiki/Object-oriented_programming[^],
http://en.wikipedia.org/wiki/Encapsulation_in_object-oriented_programming[^].
 
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: http://en.wikipedia.org/wiki/Abstraction[^], and then this: http://en.wikipedia.org/wiki/Abstraction_%28computer_science%29[^], and this: http://en.wikipedia.org/wiki/Abstraction_in_object-oriented_programming#Abstraction_in_object_oriented_programming[^].
 
—SA
  Permalink  
Comments
awaisdar at 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 at 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?
SAKryukov at 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,
--SA
Monjurul Habib at 11-Dec-11 22:21pm
   
perfect answer,5++, some people never want to read any article, how come they always expect spoon feeding.
SAKryukov at 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.
--SA
SAKryukov at 11-Dec-11 22:41pm
   
And by the way, look at some more comments. You always come across the lovers of spoon feeding. :-)
--SA
sanjy1 at 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.
SAKryukov at 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?
--SA
awaisdar at 11-Dec-11 22:40pm
   
hey stop guys.
this was simple question thought it could help many.
but this not right to fight
SAKryukov at 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).
--SA
sanjy1 at 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?
"Forums"
SAKryukov at 11-Dec-11 22:47pm
   
Please be so kind to let me decide where to be. Be a bit considerate.
 
Case closed, I hope.
--SA
Abhinav S at 12-Dec-11 0:45am
   
5 of course.
SAKryukov at 12-Dec-11 0:47am
   
Thank you, Abhinav.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Monjurul Habib at 11-Dec-11 10:16am
   
5!
Abhinav S at 11-Dec-11 12:08pm
   
Thank you.
RaviRanjankr at 11-Dec-11 10:28am
   
My 5!
Abhinav S at 11-Dec-11 12:08pm
   
Thanks Ravi.
Wonde Tadesse at 11-Dec-11 13:16pm
   
5+
Abhinav S at 11-Dec-11 13:20pm
   
Thank you Wonde.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

Encapsulation:

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

RealWorldExample:

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()
  {
    Count++;
  }
}
 
 
Although the member variable can be directly accessed, the data and its method is encapsulated in a class.

DataHidding:

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.

 
Abstraction:

 

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.
  Permalink  
Comments
sanjy1 at 11-Dec-11 23:40pm
   
:) Cheers
awaisdar at 13-Dec-11 10:53am
   
thanks
Member 9667113 at 16-Jan-13 12:43pm
   
sm one pls tell me the exact diff b/w all above three concepts of oops
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

In addition to above answers. I will suggest you to view the given practical video.
What is the difference between Abstraction and Encapsulation[^]
  Permalink  
Comments
Monjurul Habib at 11-Dec-11 20:28pm
   
nice link 5!
RaviRanjankr at 12-Dec-11 2:38am
   
Thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
awaisdar at 11-Dec-11 10:22am
   
listen i have read much aobut it. give some real world example and one prgramming

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 11 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100