Using OOP in themes

I see a lot of plugins making use of object-oriented coding when there isn’t really necessary. But what’s even worse is that theme developers are starting to do the same thing. Commercial themes and free popular themes like Suffusion, even my favorite theme – Hybrid, stuff all their functions inside a class, instantiate it once … Read more

Meaning of @classmethod and @staticmethod for beginner? [duplicate]

This question already has answers here: Difference between staticmethod and classmethod (33 answers) Closed 3 years ago. Could someone explain to me the meaning of @classmethod and @staticmethod in python? I need to know the difference and the meaning. As far as I understand, @classmethod tells a class that it’s a method which should be … Read more

Understanding Python super() with __init__() methods [duplicate]

This question already has answers here: What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__() (11 answers) Closed 6 years ago. Why is super() used? Is there a difference between using Base.__init__ and super().__init__? class Base(object): def __init__(self): print “Base created” class ChildA(Base): def __init__(self): Base.__init__(self) class ChildB(Base): def __init__(self): … Read more

Difference between staticmethod and classmethod

What is the difference between a function decorated with @staticmethod and one decorated with @classmethod? 3 33 Maybe a bit of example code will help: Notice the difference in the call signatures of foo, class_foo and static_foo: class A(object): def foo(self, x): print(f”executing foo({self}, {x})”) @classmethod def class_foo(cls, x): print(f”executing class_foo({cls}, {x})”) @staticmethod def static_foo(x): … Read more

Polymorphism vs Overriding vs Overloading

The clearest way to express polymorphism is via an abstract base class (or interface) public abstract class Human{ … public abstract void goPee(); } This class is abstract because the goPee() method is not definable for Humans. It is only definable for the subclasses Male and Female. Also, Human is an abstract concept — You cannot create … Read more