joegasewicz / flask-file-upload

Easy file uploads for Flask.
MIT License
154 stars 15 forks source link

Refactor FileUpload class by extracting file management and database operations #131

Open gelycot opened 12 months ago

gelycot commented 12 months ago

The FileUpload class currently has multiple responsibilities, including managing files and performing database operations. This leads to a violation of the Single Responsibility Principle (SRP). To improve code maintainability and readability, we should consider refactoring the class by extracting these responsibilities into separate classes.

  1. Extract File Management:

The FileUpload class is responsible for handling file uploads, deletions, and URL generation. To enhance code organization and maintainability, we propose creating a new class, FileManager, to handle all file-related operations. This separation of concerns will make the codebase cleaner and more comprehensible.

Proposed Changes:

Create a FileManager class that encapsulates file upload, deletion, and URL generation. Modify FileUpload to use the FileManager class for file operations.

  1. Extract Database Operations:

The FileUpload class currently interacts with the database directly. To adhere to the SRP and improve code modularity, we recommend creating a separate class, DatabaseManager, to handle database operations.

Proposed Changes: Develop a DatabaseManager class that manages interactions with the database. Refactor FileUpload to utilize the DatabaseManager for database-related tasks.

By implementing these changes, we aim to make the codebase more maintainable, testable, and in line with the principles of good software design.