Posts

Showing posts from January, 2016

Difference between Python classmethod and staticmethod with a better use case.

Personally, in python I believe, classmethod's and staticmethod's are about the use in terms of the case. When it comes to classmethod and instance method, the point is about you are maintaining a state (variables) to be processed. Couple of days back, I was working on the payment gateway implementation and have come across this best way to understand how to know what is good for the situation. Let's say we have three class, BasePaymentGateway FirstPaymentGateway SecondaryPaymentGateway Now, the BasePaymentGateway provides all the signature which the other payment gateways can follow. Considering the fact that each payment gateways will have their own settings and hence we need to fetch the settings from their respective item. # paymentgateway.py import settings import some_util class BasePaymentGateway(object): @staticmethod def get_payment_settings(): """Provides the settings for the given item"""