Forum guidelines
Advantages of abstraction
Posted By Yasmine Amin on 30 Jul 2008


I have a question about abstraction. I just finished reading OOPS Concepts and .NET Part 2: Inheritance, Abstraction, & Polymorphism which was a really good article and very helpful start to OOP capabilities but I still don’t understand the advantages of abstraction.

 For example, say I have a parent class called A with an abstract method getInfo(). Say the Class A has 2 child classes called B and C. Both B and C have an overridden method called GetInfo().// code in blue

The code in orange doesnt have abstraction, just 2 classes B and C inheiting a property form parent class A. so my question is why the code in blue better than the code in orange, in other words what is the advantages of abstraction.

                                                Class A
                                                getInfo() //abstract method

Class B                                                                                    Class C
getInfo() //override method                                                         getInfo() //override method

                                                            Class A

Class B                                                                                                                                          Class C

GetB() //just another function which has the same code as ClassB.getInfo()     
                                GetC() //just another function which has the same code as ClassC.getInfo()


 Thanks in adavance and i hope that my question makes sense

Re: Advantages of abstraction
Posted By Arshad on 30 Jul 2008  
Hi, well we know that we cant create the object of abstract class but it has to be Inherite,I will tell you one real time Example like a bank account. People can have savings accounts, checking accounts, credit accounts, investment accounts, but not the generic bank accounts. In this case, bank account can be an abstract class and all the other specialized bank accounts inherit from bank account, thats all

Re: Advantages of abstraction
Posted By Yasmine Amin on 30 Jul 2008  
Thank you khan for your reply but i still dont get the advantage of abstraction. i mean in the example you mentioned u can use inheritance why would use abstraction too??? i mean whats the point of declaring some method in a base class abstract that has no code in it  and then inherit that method in a sub class  and then have the code there.. i just dont see the point in inheriting something thats empty and cannot be instantiated.. i mean the abstract method is totally useless so why write the extra code.

thanks again

Re: Advantages of abstraction
Posted By Mahesh Chand on 30 Jul 2008  

Abstraction in OOP is used by advanced designers and architects when they design their class libraries that may be used by some developers and used to enforce some design rules. If you have a class library and you want to make sure the users of that class library must inherite a class and must override some methods before they can even use the library. By enforcing this rule, you may be doing login in this class ( say initialization of some engine defined ), your class library makes sure it has what it needs to execute next peice of code.

Here is a detailed reading on abstract classes:

Abstract Classes And Methods

This is a detailed analysis of Abstract classes and methods in C# with some ... The keyword abstract can be used with both classes and methods in C# to ...

C# Corner
Re: Advantages of abstraction
Posted By Sunny Chen on 31 Jul 2008  

I suggest you read Design Patterns along with your studying. This will much help on your understanding of abstraction, interfaces, overriding and other OOAD concepts.


Sunny Chen

> National Certified System Analyst
> Consultant of China System Analyst Institution

Personal Site:

C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.