vendredi 29 novembre 2019

Gracefully pattern for the useful class like a "Schemes by inheritance"

Imagine, we have a some files:
scheme.py
scheme.One.py
scheme.Two.py
sceme.*.py
...

In file scheme we have the common class code with all class attributes we need.

class Scheme:
    _VAR = "Variable"
    def function_common(self):
        pass
    def function_first(self):
        return "Main_Scheme"
    def function_second(self):
        return "Common_Scheme"

In other files we have the ONLY PARTICULAR attributes, which we want to replace in common class.

File 'scheme.One.py':

class Scheme:
    _VAR = "Scheme1"
    def function_first(self):
        return "Scheme_One"

File 'scheme.Two.py':

class Scheme:
    _VAR = "Scheme2"
    def function_second(self):
        return "Second_Scheme"

We need to determine the close scheme by some parameters (not in question) and get the appropriate class Scheme.
What is the best practice for this case, if we need to get like a "Factory of classes" in file 'scheme.py'?
I'm not PRO in Python.
Please, thorough answer...
Any Python version (>=3.74), appreciate for modern solutions...
Thanks very much!!!

Aucun commentaire:

Enregistrer un commentaire