Click here to Skip to main content
15,867,568 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. ?
Posted
Comments
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...
 
Share this answer
 
Comments
sanjy1 11-Dec-11 23:34pm    
this is awsome.
i must appreciate you.
5!
Atul Khanduri 5-Dec-13 15:22pm    
Very nice explanation....:)
My 5....
awaisdar 11-Dec-11 23:35pm    
nicely explained.
thanks!

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.
 
Share this answer
 
v2
Comments
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
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
 
Share this answer
 
Comments
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,
--SA
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.
--SA
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.
 
Share this answer
 
Comments
Monjurul Habib 11-Dec-11 10:16am    
5!
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    
5+
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):

C#
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:


C#
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.
 
Share this answer
 
Comments
sanjy1 11-Dec-11 23:40pm    
:) Cheers
awaisdar 13-Dec-11 10:53am    
thanks
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[^]
 
Share this answer
 
Comments
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
 
Share this answer
 
Comments
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.
 
Share this answer
 

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