Static methods and designing for inheritance

Inheritance clearly means a knowledge of the base class. @staticmethod is ignorant of the class it is ‘attached’ to(hence they earlier-not now-a-days-called it ‘unbound;’ now technically @staticmethod is not a method at all; it is a function.

But @classmethod is fully aware of the class it is attached to; it is technically not a function, but a method.

Why then @staticmethod at all? It is inherited in a derived class, but as said earlier, without the knowledge of base class; we can use it ‘as such’ as if we have defined it in the derived class.

Non-technically speaking @classmethods are ‘bounded’; @staticmethods are NOT.

Had anybody asked me I would have suggested the name @staticfunction for @staticmethod.

Additionally, to ensure that the latest staticmethod is called, you may use type(billy).can_climb(mountain) or billy.__class__.can_climb(mountain) (although type(billy) is more pythonic it seems), which calls the staticmethod from billy‘s (sub)class. If it’s not overridden, it would use the base-classe’s staticmethod.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)