Last post Feb 16, 2011 04:51 AM by LudovicoVan
Feb 14, 2011 04:35 AM|CsharpAsp.net|LINK
I know the concepts of Inheritance and Polymorphism in OOPS but cannot differentiate b.w Abstraction and Encapsulation.
Could anyone explain diff b/w these two together with some c# examples.
Feb 14, 2011 04:43 AM|lasantha|LINK
Feb 14, 2011 04:45 AM|Rajneesh Verma|LINK
Abstraction is virtual class design.
Before actually defining class, developer will think about what all properties,methods and event will be there in my class.
Whereas,encapsulation is data hiding.
At the time of class defenation,developer will think about which should display to end user and which should not.
In Short Abstraction is "Collection of data" and Encapsulation is "Exposure (or grouping) of data in appropriate access specifier".
see some useful links:
Feb 14, 2011 06:03 AM|CsharpAsp.net|LINK
Sorry the above links dont explain these concepts well.
In some its written Encapsulation is data hiding and in some abstraction is data hiding.
Feb 14, 2011 06:34 AM|hassanmehmood|LINK
Abstraction is what you think about an entity in your real life. Like a CAr. It has wheels steering chasis color etc etc etc.This is abstration. Just think about something and you are gathering info about it. And yes.. that info is actually the properties,
methods, variables of a class representing that entity.
Encapsulation is what a class will show to the user of it. May be you want to give a developer the access to the field Color. So that he can set the color of the car (You make it public for this purpose) But you don't want to give access to the developer
for the field NoOfWheels. so that he couldn't set it to some odd no. (so u make it private). This is Encapsulation.
And wherever you see "Abstraction is data hiding" just post a comment saying "It is Wrong". Encapsulation is Data Hiding and Abstraction is Data Gethering
Hope this helps..
Feb 14, 2011 07:04 AM|pinet|LINK
Well the concepts Encapsulation and Abstraction are defined differently by different writers and mostly these are intermixed,
Encapsulation: Means "we have enclosed all the characteristics of an object in the object itself" like we add all image related attributes and methods in Image class , internet related characteristics in System.Net and so on....
Abstraction: Hiding more complicated details from user and providing him only his relevant details to the extent he needs like we expose methods in classes in interfaces of CSharp or java, Driver calls, Dll calls, Encryption Library calls, AVI Library calls
[However you might find different definitions at some other places but these are most appropriate as far as I understand].
Feb 14, 2011 08:20 AM|CsharpAsp.net|LINK
Yes Even in this post I am finding different definations.
Feb 15, 2011 04:34 AM|CsharpAsp.net|LINK
Anyone else with some inputs
Feb 16, 2011 04:47 AM|CsharpAsp.net|LINK
No one for any other inputs
Feb 16, 2011 04:51 AM|LudovicoVan|LINK
In logical order, the three concepts that pertain to OO are:
1 - Encapsulation
2 - Inheritance
3 - Polymorphism
Of the three, the first is foundational and has to do with hiding the implementation; the second and third are more advanced concepts and were introduced (IIRC) by B. Stroustrup at a later time during the development of the OO theory. -- Abstraction, OTOH,
is simply not an OO concept...