Pick the fix
A PaymentProcessor has a growing when (method) with card, PayPal and Google Pay branches, each with a lot of code. Adding a method keeps breaking others. Best change?
Hint 1 of 1
How can you add a method without editing the others?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Give each method its own implementation of a PaymentMethod interface
Correct. New methods are new classes; existing ones aren't touched.
Why not the others?
- B Add comments separating the branches. Doesn't reduce coupling.
- C Move the when into the ViewModel. Moves the problem up.
- D Use reflection to call methods by name. Loses type safety.