Skip to content

Adding solution for day 19#12

Open
yanncourtel wants to merge 39 commits into
advent-of-craft:mainfrom
yanncourtel:main
Open

Adding solution for day 19#12
yanncourtel wants to merge 39 commits into
advent-of-craft:mainfrom
yanncourtel:main

Conversation

@yanncourtel
Copy link
Copy Markdown
Contributor

The idea here was to add taxes to the invoice statement.

I added in the unit test solution a refactoring map with all steps I used.

yanncourtel and others added 30 commits December 4, 2025 11:16
Solution/day03 - Try at day02 in Kotlin
Restructure documentation into two focused files:
- 01-tax-calculation-overview.md: Business requirements and feature scope
- 02-tax-calculation-roadmap.md: Analysis, gaps, and implementation strategy

Refs: Phase 1 - Analysis Complete
Add PrintWithTaxes method to support regional tax calculation while
maintaining backwards compatibility with existing Print method.
The refactoring map has two primary goals.

1) Identify missing domain concepts
2) Prioritize the refactoring tasks in phases with the lesser risks first.
… a static readonly field

Ref: Docs/03-tax-calculation-refactoringmap.md
Part of Phase 1: Extract Helpers
Extract tax rate lookup logic into GetTaxInfo helper.
Centralizes error handling for unknown regions and provides
consistent access to tax information.

Ref: Docs/03-tax-calculation-refactoringmap.md
Part of Phase 1: Extract Helpers (Complete)
Create EnrichedDelivery class to encapsulate delivery with its company,
eliminating manual relationship resolution in business logic.
Add EnrichedInvoice domain model and new Print methods that accept it,
eliminating dictionary parameter from core printing logic.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 1.5: Domain Model Coherence (Complete)
Handle money formatting and value calculation.
Add public factory from cents or dollar amount.

Add EnrichedInvoice domain model and new Print methods that accept it,
eliminating dictionary parameter from core printing logic.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 2: Create Money struct with AmountInCents property (complete).
Create Tax value object to encapsulate tax region, rate, and amount.
Replaces scattered tax data with cohesive domain object.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 2: Tax Value Object (complete)
…ggregate

Add InvoiceLine object for better encapsulation.
Create CalculatedInvoice to represent fully calculated invoice data.
Completes separation between calculation and formatting.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 3: Created InvoiceLine and CalculatedInvoice (phase 3: complete)
Enhance domain model with better encapsulation following Law of Demeter
and C# conventions for string representation.

Post phase 3 refactoring
Extract all formatting logic into dedicated formatter classes implementing
IInvoiceFormatter interface. InvoicePrinter now focuses purely on business
logic (enrichment and calculation).

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 4: Extract Formatters
… default one.

Simplified the injection of formatters.
Added factory for service under test
Split package strategy for calculation cost.
Add extensions for enriched delivery for better syntax in invoice printer.
Add unit tests for calculation.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Extract Pricing.
Extract tax calculation logic into dedicated TaxCalculator class.
Moves tax rates and calculation logic out of InvoicePrinter.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Extract Tax Calculation.
Add extensions in each node of the domain model.
Simplify the invoice printer.

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Extract Tax Calculation.
Extract class for loyalty calculation
Add extensions for bridge
Simplify the call from InvoicePrinter

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Extract Loyalty Calculation.
Moving factory method into the InvoiceLine
Simplify InvoicePrinter
Add InvoiceCalculator class and inject all calculation service
Adjust the InvoicePrinter
Remove all extensions that was holding business logic

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Create Domain Service.
Add Loyalty calculation tests
Add Tax calculation test

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 5: Added calculation unit tests (complete).
Replace string by Region enum
Remove TaxRate Model
Remove all methods not used

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 6: Adjust TaxRate object (remove unused TaxRate).
Add Invoice extensions to enrich it
Add EnrichInvoice extensions to allow calculation
Add CalculatedInvoice extensions to allow formatting

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 6: Add Extension Methods for Declarative Syntax.
…ctics.

Move files into 3 folders: Domain, Formating and Calculation
Move extensions to be on the consumer side to bridge domains

Ref: Docs/03-tax-calculation-refactoringmap
Part of Phase 6: Package Organization (DDD Tactical Patterns).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant