LLD - Design — Online Shopping CartWhich 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;Check Answer
Step-by-Step SolutionSolution:Step 1: Identify the correct syntax for an interfaceIn object-oriented languages, interfaces declare method signatures without implementation. interface PaymentStrategy { void pay(double amount); } uses 'interface' and a method signature correctly.Step 2: Check other optionsclass PaymentStrategy { void pay(amount); } is a class, not an interface. Options C and D use function syntax, not interface definitions.Final Answer:interface PaymentStrategy { void pay(double amount); } -> Option AQuick Check:Interface syntax = interface PaymentStrategy { void pay(double amount); } [OK]Quick Trick: Look for 'interface' keyword and method signature format [OK]Common Mistakes:MISTAKESUsing class instead of interface for strategy definitionConfusing function syntax with interfaceMissing method parameter types
Master "Design — Online Shopping Cart" in LLD9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepArchTryChallengeDesignRecallScale
More LLD Quizzes Advanced LLD Concepts - Code review checklist for LLD - Quiz 1easy Design — Chess Game - Observer pattern for UI updates - Quiz 4medium Design — Chess Game - Board and piece hierarchy - Quiz 3easy Design — Chess Game - Why chess tests polymorphism and strategy - Quiz 13medium Design — Food Delivery System - Restaurant, Menu, Order classes - Quiz 7medium Design — Food Delivery System - Notification to all parties - Quiz 15hard Design — Food Delivery System - Rating and review system - Quiz 9hard Design — Hotel Booking System - Cancellation and refund policy - Quiz 13medium Design — Online Shopping Cart - Product, Cart, Order classes - Quiz 8hard Design — Splitwise (Expense Sharing) - Simplify debts algorithm - Quiz 13medium