B
B
Boris2019-11-30 17:04:25
Python
Boris, 2019-11-30 17:04:25

How to make a kind of "Factory" to support peculiar "Configurations" with such inheritance features?

Suppose there are several files:
scheme.py
scheme.One.py
scheme.Two.py
scheme.*.py
***
In the scheme.py file, the Scheme class is declared with all the attributes that are generally necessary:

class Scheme:
    _VAR = 'Common Scheme Class'
    def function_common(self):
        return 'Function Common'
    def function_first(self):
        return 'Function First'
    def function_second(self):
        return 'Function Second'

For ease of maintaining configurations, the files that change the behavior of the Scheme class will be something like this:
The scheme.One.py file:
class Scheme:
    _VAR = 'One Scheme Class'
    def function_first(self):
        return 'Function One'

File scheme.Two.py:
class Scheme:
    _VAR = 'Two Scheme Class'
    def function_second(self)
        return 'Function Two'

This solution is not suitable (classical inheritance):
In template files (scheme.One.py, scheme.Two.py, etc.), it would be possible to inherit from the general Scheme class with all possibly necessary attributes and override the necessary ones, for example :
class SchemeOne(Scheme):
    _VAR = 'One Scheme Class'
    def function_second(self):
        return 'Function Seconf Two Scheme Class'
    def function_third(self):
        return 'Function Third'

I want each file to have a class, namely, with the name "Scheme", for ease of implementation of support for template modules by end users. In this case, one of the methods of the Scheme class could bypass all such files and select one to override the base class (even if only based on the _VAR attribute), replace from it the necessary (present in the selected extension file) attributes in the original Scheme class and return the final class.
On StackOverflow, I was advised, in fact, the "Class Factory" ... Which is good ... But a little different ...
If I understand correctly, I need to manually rip out the attributes from one and shove them into another class - how to do this functional?
Or am I reinventing the wheel? Maybe someone sees this picture differently?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question