-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
The model class currently contains direct HTTP-related knowledge, specifically in the implementation of self._client.post() calls within the model layer. This creates tight coupling between the model and the HTTP communication layer.
e.g.:
barte-python-sdk/barte/models.py
Lines 46 to 47 in c564f40
| from .client import BarteClient | |
| return BarteClient.get_instance().refund_charge(self.id, {"amount": amount} if amount else None) |
Problem
This coupling:
- Violates the Single Responsibility Principle (SRP) - models should only be responsible for business logic and data structure
- Makes the code harder to test as model tests need to mock HTTP calls
- Reduces code reusability as the models are tightly coupled to a specific HTTP implementation
- Makes it difficult to change the communication layer without modifying model classes
Proposed Solution
Implement a proper separation of concerns by:
- Keep models focused only on data structure and business logic
- Use dependency injection to handle communication needs
Benefits
- Improved testability: Models can be tested in isolation without HTTP mocking
- Better maintainability: Changes to HTTP communication won't affect model layer
- Enhanced flexibility: Easier to implement different communication methods
- Cleaner architecture: Clear separation between data models and communication
- Better adherence to SOLID principles
Implementation Notes
- Update models to receive necessary dependencies through constructor injection
- Move HTTP-specific logic to the service layer
- Update tests to reflect the new architecture