Skip to content

refactor: replace long, ugly switch..case statements with visitor pattern#9

Open
nicolasduminil wants to merge 1 commit intomyfear:mainfrom
nicolasduminil:refactor/visitor-pattern
Open

refactor: replace long, ugly switch..case statements with visitor pattern#9
nicolasduminil wants to merge 1 commit intomyfear:mainfrom
nicolasduminil:refactor/visitor-pattern

Conversation

@nicolasduminil
Copy link
Contributor

Description

Refactored event sourcing code to eliminate these long and ugly switch..case statements and implement the visitor pattern.

Changes

  • Added applyTo(), getEventType(), and getEventClass() methods to OrderEvent sealed interface
  • Each event record now encapsulates its own application logic
  • Simplified EventProjection by delegating to event.applyTo()
  • Removed switch statements from EventStore by using an EVENT_TYPES registry
  • Improves code maintainability and follows the visitor pattern

Testing

  • All existing tests pass
  • No functional changes, only structural improvements

…rcing

- Add applyTo(), getEventType(), and getEventClass() methods to OrderEvent sealed interface
- Each event record now encapsulates its own application logic
- Simplify EventProjection by delegating to event.applyTo()
- Remove switch statements from EventStore by using EVENT_TYPES registry
- Improves maintainability and follows visitor pattern
@myfear
Copy link
Owner

myfear commented Mar 7, 2026

Thank you @nicolasduminil ! Would you be so kind to also include article updates so I can keep this in sync?
Thanks!

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.

2 participants