Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override empty methods in inheritance

Tags:

c#

oop

Need a bit of OOP help.

I have a base payment consisting of SendPayment() UpdateRecord() then child classes implementing different payment formats e.g. PayPal, SagePay.

While all have SendPayment() method they are all implemented differently. So I override the base class to apply my own implementation in each child class. The base classes do not hold any implementation just empty methods. Is this a good way of OOP to have empty methods then implement override code in each child class or remove the empty methods in the base and have these methods in the child classes?

thanks...

Sorry a quick edit. I do use the base class for certain scenarios for example calculation. This covers all payment types such as counting how many products by the cost and removing records from the table.

like image 648
James Andrew Smith Avatar asked Mar 08 '26 22:03

James Andrew Smith


1 Answers

I would suggest to make your base class as abstract class and make the unimplemented method as abstract method.

    public abstract class BasePayment {

        //abstract method: unimplemented        
        public abstract void sendPayment();

        //implemented method    
        public void UpdateRecord(){
            .....
        }

    }

Abstract class is meant for this kind of scenarios where you want to have mix of implemented and unimplemented method. One added advantage here is: Every extending class will be forced to implement its own sendPayment method.

like image 163
Yogendra Singh Avatar answered Mar 10 '26 12:03

Yogendra Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!