Ad Code

Purpose of defining inheritance relationship?

What is the purpose of defining inheritance relationship? I mean in example given Cash Payment, Cheque and Charge are child classess of Payment.   Why I wrote Payment class in the first place,  in system I will be using objects of either Charge, Cash payment or Cheque; then why we exclusively wrote Payment class first and then inherits from it;  although we are not using its object in the system.  Isn't it just increasing the code writing process; kindly explain?


Purpose of inheritance is enhancing code reusability. Payment class is made parent class and cheque, charges and cash payment are child classes in given example. We have done it for reuse purpose. Later when you need any of these functionalities, the method of class Payment will be inherited by sub classes allowing us not to repeat those methods in sub classes again. In this way, it is not increasing code writing rather it is promoting code reuse and hence it will save our time. 
Reactions

Post a Comment

0 Comments