Bird
Raised Fist0

Which of the following is the correct way to define a payment strategy interface in a typical object-oriented language?

easy🧠 Conceptual Q12 of Q15
LLD - Design — Online Shopping Cart
Which of the following is the correct way to define a payment strategy interface in a typical object-oriented language?
Ainterface PaymentStrategy { void pay(double amount); }
Bclass PaymentStrategy { void pay(amount); }
Cfunction PaymentStrategy(amount) { return pay; }
Dvar PaymentStrategy = pay => amount;
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct syntax for an interface

    In object-oriented languages, interfaces declare method signatures without implementation. interface PaymentStrategy { void pay(double amount); } uses 'interface' and a method signature correctly.
  2. Step 2: Check other options

    class PaymentStrategy { void pay(amount); } is a class, not an interface. Options C and D use function syntax, not interface definitions.
  3. Final Answer:

    interface PaymentStrategy { void pay(double amount); } -> Option A
  4. Quick Check:

    Interface syntax = interface PaymentStrategy { void pay(double amount); } [OK]
Quick Trick: Look for 'interface' keyword and method signature format [OK]
Common Mistakes:
MISTAKES
  • Using class instead of interface for strategy definition
  • Confusing function syntax with interface
  • Missing method parameter types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes