0

I want to to implement some classes with the same static variables for the all classes. I want to restrict those classes to have same structure. so I want to use abstract class. but I have problem to achieve this methodology with abstract class. those variables need to be static because there isn't situation those variables change. I just want to "collect" some variable "under the same roof"

example:

class FirstChild(Father):
     first_static_variable = "value to first_static_variable in first child"
     second_static_variable = "value to second_static_variable in first child"


class SecondChild(Father):
     first_static_variable = "value to first_static_variable in second child"
     second_static_variable = "value to second_static_variable in second child"


class Father(ABC):
     #here I want to force Father childs to have first_static_variable and second_static_variable
amit
  • 71
  • 2
  • 10
  • I don't understand your question, but maybe use a tuple. – Fiddling Bits Aug 19 '22 at 17:14
  • what don't you understand? – amit Aug 19 '22 at 17:15
  • 3
    Does this answer your question? [Abstract attribute (not property)?](https://stackoverflow.com/questions/23831510/abstract-attribute-not-property) – Abdul Aziz Barkat Aug 19 '22 at 17:19
  • Can you show a circumstance where something fails because one of the child classes has failed to define one of its static variables? (aka class attributes) – quamrana Aug 19 '22 at 17:19
  • I want to direct the next programmer to implement similar class with those variables. There is script that run and do Child.first_static_variable And I don't this script to fail. – amit Aug 19 '22 at 17:26

0 Answers0