Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Mixins #485

Open
Gorkowski opened this issue Oct 4, 2024 · 0 comments
Open

Refactor Mixins #485

Gorkowski opened this issue Oct 4, 2024 · 0 comments
Labels
sourcery-ai sourcery-ai

Comments

@Gorkowski
Copy link
Collaborator

issue (complexity): Consider consolidating the multiple mixin classes into a single builder class with optional configuration methods.

The current implementation using numerous small mixin classes introduces unnecessary complexity. While it provides flexibility, it fragments functionality across many classes, potentially making the code harder to understand and maintain. Consider consolidating these mixins into a single builder class with optional configuration methods. This approach would maintain flexibility while simplifying the class structure.

Here's a suggested refactoring:

class DataLoaderBuilder:
def init(self):
self.config = {}

def set_relative_data_folder(self, folder: str):
    self.config['relative_data_folder'] = folder
    return self

def set_filename_regex(self, regex: str):
    self.config['filename_regex'] = regex
    return self

def set_file_min_size_bytes(self, size: int = 10000):
    self.config['file_min_size_bytes'] = size
    return self

# ... other setter methods ...

def build(self):
    return DataLoader(self.config)

class DataLoader:
def init(self, config):
self.config = config

# ... methods to use the configuration ...

This approach:

Reduces the number of classes, simplifying the overall structure.
Maintains the flexibility to configure only what's needed.
Avoids potential issues with multiple inheritance.
Keeps all related configuration in one place, improving readability.
Still allows for easy extension by adding new methods to the builder.
This refactoring preserves the functionality while significantly reducing the complexity of the class structure.

@mahf708 mahf708 added the sourcery-ai sourcery-ai label Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sourcery-ai sourcery-ai
Projects
None yet
Development

No branches or pull requests

2 participants