Refactoring Code Base #55
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Forked repo to share
Hey @re-leased-hiring here is my pull request
I've created a comprehensive refactoring of the entire codebase, including updated tests. Here's an overview of what's included:
Refactored Domain Classes
Invoice Class: Now follows proper domain-driven design with rich behavior
Encapsulates payment processing logic
Provides clear property access control
Includes helpers for testing
Uses rich domain vocabulary with enums
Payment Class: Added with proper validation and constructors
Repository Pattern Implementation
IInvoiceRepository Interface: Creates a contract for repository operations
InvoiceRepository: Maintains backward compatibility while adding new features
ModernInvoiceRepository: A cleaner implementation for new code
Refactored Service Layer
InvoiceService: Now acts as a thin facade over domain operations
Maps domain results to user-friendly messages
Handles repository interactions
Validates inputs
Updated Tests
Fixed to work with the new domain model
Added a meaningful reference for better traceability
Includes setup method for better test organization
Added test for tax calculation on commercial invoices
Key Design Improvements
Proper Separation of Concerns
Domain logic moved to domain objects
Repository handles persistence concerns
Service layer handles orchestration
Improved Domain Model
Invoice now has rich behavior and enforces its own business rules
Payment results communicate outcomes clearly
Properties are properly encapsulated
Backward Compatibility
Repository maintains compatibility with old code
Helper methods support testing scenarios
Future-Proofing
Interface-based design supports dependency injection
Testable components with clear responsibilities
Support for multiple invoice storage