Can i decorate child methods with parent method where i extract some common code? The Design and structure of classes must be preserved. I have:
class Parent:
def general_create(self, create_child_func):
def wrapper(*args, **kwargs):
print("Some general actions before")
result = create_child_func(*args, **kwargs)
print("Some general actions after")
return result
return wrapper
class A(Parent):
def create(self):
print("Сreate actions for class A")
return "Result A"
class B(Parent):
def create(self):
print("Сreate actions for class B")
return "Result B"
I thought it should be like this (but of course it doesn't work):
class Child(Parent):
@Parent.general_create # or @super().general_create
def create(self):
print("Сreate actions for class Child")
return "Result Child"