Replace Conditionals with Polymorphism
Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.
The problem
- medium
- Pro
Your checkout code has a long chain of conditions checking the payment method, card, PayPal, bank transfer and so on, and it is repeated in three places. Each new payment method means editing all three. Explain the open closed principle and how you'd restructure this code.
Talk this problem through with an AI coach
This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.