0
0
LLDsystem_design~10 mins

Proxy 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 Proxy class implementing the Subject interface.

LLD
class Proxy implements [1] {
    private RealSubject realSubject;

    public void request() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        realSubject.request();
    }
}
Drag options to blanks, or click blank then click option'
AProxy
BSubject
CRealSubject
DClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using RealSubject instead of Subject as the implemented interface.
Not implementing any interface.
Implementing Proxy interface which does not exist.
2fill in blank
medium

Complete the code to forward the request from Proxy to RealSubject.

LLD
public void request() {
    if (realSubject == null) {
        realSubject = new RealSubject();
    }
    realSubject.[1]();
}
Drag options to blanks, or click blank then click option'
Arequest
Bexecute
Chandle
Dprocess
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names not defined in the Subject interface.
Calling a method that does not exist in RealSubject.
3fill in blank
hard

Fix the error in the Proxy constructor to initialize the RealSubject lazily.

LLD
public Proxy() {
    [1] = null;
}
Drag options to blanks, or click blank then click option'
Asubject
BRealSubject
CrealSubject
Dproxy
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name RealSubject instead of the variable name.
Initializing realSubject to a new RealSubject() in the constructor.
4fill in blank
hard

Fill both blanks to add access control in Proxy before forwarding the request.

LLD
public void request() {
    if ([1]()) {
        realSubject.[2]();
    } else {
        System.out.println("Access denied.");
    }
}
Drag options to blanks, or click blank then click option'
AcheckAccess
Brequest
Cvalidate
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Calling execute() instead of request() on realSubject.
Using validate() without defining it.
5fill in blank
hard

Fill all three blanks to implement caching in Proxy for the result of RealSubject's request.

LLD
private String cache;

public String request() {
    if (cache == null) {
        cache = realSubject.[1]();
    }
    return [2];
}

public void clearCache() {
    [3] = null;
}
Drag options to blanks, or click blank then click option'
Aresult
Bcache
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Returning realSubject.request() every time without caching.
Clearing the wrong variable in clearCache().