Transaction Dispute
Context
In many enterprise applications, such as payment platforms or banking systems, a transaction dispute can occur due to different reasons:
Unauthorized access
Duplicate transaction
Product not received
Service-related issues
Each type of dispute requires distinct validation and handling logic.
Problem Statement
We receive a dispute type as an enum from a request parameter in a REST controller. We want to:
Route this enum to the correct validation strategy (bean)
Call its
validateDispute()methodAvoid large if-else or switch-case blocks
Design Solution
This fits the Strategy Pattern, where:
The
enumacts as a strategy keyEach
DisputeHandleris a strategy implementationSpring injects the correct bean based on the enum at runtime
Structure
A. Dispute Type Enum
B. Strategy Interface
C. Implementations
Repeat similar beans for other dispute types.
D. Strategy Resolver Using Enum Map
E. Controller Layer
Last updated