0
0
LLDsystem_design~10 mins

Payment strategy pattern in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the PaymentStrategy interface.

LLD
interface [1] {
    void pay(int amount);
}
Drag options to blanks, or click blank then click option'
APayment
BPaymentStrategy
CPayStrategy
DPaymentMethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of an interface name.
Choosing a name that does not reflect the strategy pattern.
2fill in blank
medium

Complete the code to implement the pay method in CreditCardPayment class.

LLD
class CreditCardPayment implements PaymentStrategy {
    public void [1](int amount) {
        System.out.println("Paid " + amount + " using Credit Card.");
    }
}
Drag options to blanks, or click blank then click option'
Apay
Bprocess
CmakePayment
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than the interface.
Forgetting to implement the interface method.
3fill in blank
hard

Fix the error in the PaymentContext constructor to accept a PaymentStrategy.

LLD
class PaymentContext {
    private PaymentStrategy strategy;

    public PaymentContext([1] strategy) {
        this.strategy = strategy;
    }
}
Drag options to blanks, or click blank then click option'
AStrategy
BPaymentMethod
CPaymentStrategy
DPayment
Attempts:
3 left
💡 Hint
Common Mistakes
Using a concrete class type instead of the interface.
Mismatching parameter type and field type.
4fill in blank
hard

Fill both blanks to complete the pay method call in PaymentContext.

LLD
class PaymentContext {
    private PaymentStrategy strategy;

    public void pay(int amount) {
        strategy.[1]([2]);
    }
}
Drag options to blanks, or click blank then click option'
Apay
Bamount
Cprocess
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name like 'process'.
Passing wrong argument like 'value'.
5fill in blank
hard

Fill all three blanks to create a PaymentContext with PayPalPayment and pay 100.

LLD
PaymentStrategy strategy = new [1]();
PaymentContext context = new PaymentContext([2]);
context.[3](100);
Drag options to blanks, or click blank then click option'
APayPalPayment
Bstrategy
Cpay
DCreditCardPayment
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong payment class like CreditCardPayment.
Passing wrong variable to context.
Calling wrong method name.