I face a program like following:
# This code just used to reflect the recursive structure, DO NOT take it grammatically !!class A: def __init__(self) -> None: pass def check(self, element): if element == 'TypeA': self.__validate_TypeA(element) if element == 'TypeB': self.__validate_TypeB(element) if element == 'TypeC': self.__validate_TypeC(element) def __validate_TypeA(self, element): # implementation.. if element.contains('TypeB'): self.check('TypeB') # implementation... def __validate_TypeB(self, element): if element.contains('TypeC'): self.check('TypeC') def __validate_TypeC(self, element): if element.contains('TypeA'): self.check('TypeA') # thousands of codes here...In this class, methods are depend on each other; In my project, there are half hundreds of Types like 'TypeA', 'TypeB', and they are coorelated and might call check method in their own implementaion; now my class grows to 4 thousands of lines of code, the maintaining is becoming tricky.
I have tried using inheritence, it does not work out;I have tried using exec(), built-in, but it will forcefully break the code into multi files, losing the possiblity of using IDE for code highlighting, etc...
So is there a way to do following? :
- divide my class into multi files,might be one file for one Type implementation
- do not influence the program strcuture
In C/C++, this could be easiliy accomplished using #include, i do not know how to do it in Python.