The code in orange doesnt have abstraction, just 2 classes B and C inheiting a property form parent class A. so why the code in blue better than the code in orange, in other words what is the advantages of abstraction.
Class A
_property1;
getInfo() //abstract method
Class B Class C
getInfo() //override method getInfo() //override method
_property1;
getInfo() //abstract method
Class B Class C
getInfo() //override method getInfo() //override method
Class A
_property1;
_property1;
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()
GetB() //just another function which has the same code as ClassB.getInfo() GetC() //just another function which has the same code as ClassC.getInfo()
We know that we cant create the object of abstract class but it has to be Inherite,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
Thanks
Thanks
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
|