We help IT Professionals succeed at work.

"Abstraction" - OOPS Definition - Explanation in C# / VB.NET

20,401 Views
Last Modified: 2013-12-17
Hi,

I am looking into "OOPS" - Object Oriented Programming Concepts. I have the following definition for "Abstraction". Can you please explain / justify me this concept in simple terms ? Even though this seems to be simple but i want to understand what does this mean !!

Definition:
========

"Abstraction" refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.

Appreciate your help !
Comment
Watch Question

Abstraction, if a class which you create as abstract class, then this class is just like a blue print of the class structure without any details or process logic. And when you imply this class to any sub class then you will have to use the structure of this abstract class as blue print.
Jai STech Arch

Commented:
abstract - in plain english 'Theorotical' which means that its in theory...
so when you say that you create an abstract class it is only the DEFINITION and not the usage...
the main idea (one of the ) behind creating abstract class / methods are to list down the structure of how your derived classes must be and what methods are to be overridden by them in order to perform the DERIVED objects specific needs...
Top Expert 2004

Commented:
If you study philosophy, plato might have called it a universal.

It is an ideal... a set of functionality/properties which have been brought up to another level.

A great example of an abstraction can be seen in the definition of species ... A mammal contains similarities between both mice and humans. In its term it can easily describe that we both give birth to live young, have warm blood, and have hair. By providing the abstraction of a mammal we can talk in similarity about mice, humans, or a species you have might never heard of (The Houynhnms from Gulliver's Travels) and you can understand something about them based upon the fact that they meet the mammal abstraction.

There are many abstractions in language ... say I were to say the words 'TVR Tuscan' you may not know what they mean but if I said 'sports car' you know! ... This is because sports car is an abstraction that describes the TVR Tuscan as well as other fast, well handling, and generally desirable by males in their 20s cars..

While the above is in specific geared towards polymorphism ... In the same way; in computer science abstraction groups objects of similar  functionalities ... Abstraction can be seen as a case like the above or as simply as hiding internal details of an obect from other objects ...

Cheers,

Greg
Top Expert 2007

Commented:
Both of these responses tell you about abstract classes, but don't really hit on the concept of abstraction. The general OO concept of abstraction means that for any object, it is important to separate gory details from the picture the object presents to the outside world. For example, say you have instantiated a telephone class. There is a public method you can invoke that will tell it to dial a specific phone number. You are a consumer of that telephone class. You tell it to DIAL( 218-555-1212 ).

You do not care whether it sends tones or pulses over a copper wire or whether it routes through VOIP, you just want the telephone to place a call.

There are two advantages to that.
1. As a caller, you do not need to know anything about how telephones are dialed, and
2. The smart people who write the detail code for dialing may find a faster, better, cheaper way to do the job, and your code doesn't need to change at all.

That is the OO concept of abstraction.

Jim
Top Expert 2007

Commented:
As Greg pointed out, abstraction and polymorphism can be combined. You base mammal class might have an abstract method called Speak(). It needs to be overridden in each derived class. If you have a Dog or a Cat or an Elephant, if you invoke the Speak() method something is going to happen, and it will likely be different for each derived class.

Jim
Top Expert 2004

Commented:
Of couse for a proper abstaction you would probably not put Speak() on mammal ... surely a frog can speak yet it is not a mammal. Thus we may even end up with a SpeakingAnimal abstraction which defined Speak and all mammals (though I doubt they can all speak, note 'mute human') would thus be abstracted as SpeakingAnimals. Unfortunately while the concept of abstraction is easy to grasp in practice edge conditions (or new discoveries/forgotten cases) often cause drastic changes in your abstractions :)

Cheers,

Greg

Author

Commented:
Jim,

Great explanation. But then what is the difference between "Abstaction" and "Encapsulation" ? No difference ? These two are different in OOPS...please correct me if i am wrong !!

Author

Commented:
mmm...sorry..."Abstraction" and "Hiding"....No difference ?
Top Expert 2004

Commented:
Encapsulation can be a form of abstraction! abstraction though is a broader term. In lnguage abstraction tends to equate to polymorphism.
Top Expert 2007

Commented:
It does get to be confusing. As Greg just pointed out, encapsulation and abstraction are related. Go back to the Telephone class. All the stuff to dial a phone is encapsulated. But it doesn't do any good it you can't get to it somehow. So, you are presented with an abstraction of that Behavior in the method invocation called Dial().

Greg's mention of Frogs brings up another good point. Lots of animals can speak. In C++, I could derive Frof from Amphibian and SpeakingAnimal. I could derive Dog from Mammal and SpeakingAnimal. I think the biggest loss in the move to C# was the loss of multiple inheritance. I know it caused me to write a lot of duplicated code.

Jim

Author

Commented:
So Jim,

Thanks for your info. BTW Is this the same thing i can call "Hiding" ? Am i correct ?

Thanks

Top Expert 2007

Commented:
Correct - Encapsulation and Hiding are different terms for the same thing.

Jim

Author

Commented:
Here is the summary:

"Abstraction" and ""Hiding" are same. But "Encapsulation" is nothing but encapsulating "Members and Methods". Please correct me if i am wrong !!
Jai STech Arch

Commented:
No, Absctraction is not HIDING...Encapsulation is termed as HIDING...

Author

Commented:
In this scenario,

=================================================================================
Both of these responses tell you about abstract classes, but don't really hit on the concept of abstraction. The general OO concept of abstraction means that for any object, it is important to separate gory details from the picture the object presents to the outside world. For example, say you have instantiated a telephone class. There is a public method you can invoke that will tell it to dial a specific phone number. You are a consumer of that telephone class. You tell it to DIAL( 218-555-1212 ).

You do not care whether it sends tones or pulses over a copper wire or whether it routes through VOIP, you just want the telephone to place a call.

There are two advantages to that.
1. As a caller, you do not need to know anything about how telephones are dialed, and
2. The smart people who write the detail code for dialing may find a faster, better, cheaper way to do the job, and your code doesn't need to change at all.

That is the OO concept of abstraction.

Jim

I do not know the details behind the scenes. It is just giving me a method to invoke that object properties (ex: Dailing Phone). ?????
Top Expert 2007

Commented:
My first post on this thread came from a book I have had for a long time, called "C++ Primer+" by Stephen Prata, page 347.

Since then, I have looked at some other books and done some Googling. My conclusion is the the definition presented in this book, or my interpretation thereof, is incorrect. I apologize for creating confusion by presenting that as THE definition. It was one definition, and it was incorrect.

Based on further reading, Greg's first post is much close to the mark.

Jim

Author

Commented:
BTW:

Can any body give the exact definition for this so that i can close my listing please ? Appreciate your time and effort !!

Thanks
Top Expert 2004
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Jai STech Arch

Commented:
i would suggest a point split between jimbrandley and gregoryYoung
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.