Forums - C# Corner

Forum guidelines

Advantages of abstraction

Jul 30 2008 6:41 AM


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

Answers (4)