Apply Strategy pattern for multiple payment methods
Reported in trivago European engineering loops. OOD pattern question focused on replacing condition-heavy logic.
Interview scenario
Context for trivago candidates:
Support card, UPI, wallet, and net banking with clean extensible design.
Model answer
Try answering aloud first
Cover trade-offs, structure, and a concrete example before revealing the baseline response.
How to frame this at trivago: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.
Define a common PaymentStrategy interface with methods like authorize and capture. Concrete strategies implement provider-specific behavior while checkout flow depends only on the interface.
This removes large if-else branches and allows adding new methods without modifying stable orchestration code. Pair Strategy with factory or dependency injection to select implementation at runtime.
Interviewers like hearing about testability gains: each strategy can be unit tested independently with mocked gateway clients.
Discussion
Comments (0)
Share how this question came up in your loop, or add tips for others preparing.
Log in to comment on this question.