Bird
0
0
LLDsystem_design~10 mins

Observer 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 Observer interface method.

LLD
interface Observer {
    void [1]();
}
Drag options to blanks, or click blank then click option'
Aupdate
Bnotify
Clisten
Dalert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notify' which is a keyword in some languages.
Using 'listen' or 'alert' which are not standard method names here.
2fill in blank
medium

Complete the code to add an observer to the subject's list.

LLD
class Subject {
    private List<Observer> observers = new ArrayList<>();

    public void [1](Observer o) {
        observers.add(o);
    }
}
Drag options to blanks, or click blank then click option'
Aattach
BregisterObserver
CaddObserver
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'attach' which is less common in Java-style code.
Using 'subscribe' which is more common in event-driven systems.
3fill in blank
hard

Fix the error in the notifyObservers method to correctly call update on each observer.

LLD
public void notifyObservers() {
    for (Observer o : observers) {
        o.[1]();
    }
}
Drag options to blanks, or click blank then click option'
Aalert
Bnotify
Crefresh
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notify' which is not defined in Observer interface.
Using 'refresh' or 'alert' which are not standard method names.
4fill in blank
hard

Fill both blanks to complete the Subject class with observer management methods.

LLD
class Subject {
    private List<Observer> observers = new ArrayList<>();

    public void [1](Observer o) {
        observers.add(o);
    }

    public void [2](Observer o) {
        observers.remove(o);
    }
}
Drag options to blanks, or click blank then click option'
AaddObserver
BremoveObserver
CregisterObserver
DunregisterObserver
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing method names like 'registerObserver' with 'unregisterObserver' inconsistently.
Using 'subscribe' or 'unsubscribe' which are less common here.
5fill in blank
hard

Fill all three blanks to complete the Observer pattern update flow.

LLD
interface Observer {
    void [1]();
}

class Subject {
    private List<Observer> observers = new ArrayList<>();

    public void [2](Observer o) {
        observers.add(o);
    }

    public void notifyObservers() {
        for (Observer o : observers) {
            o.[3]();
        }
    }
}
Drag options to blanks, or click blank then click option'
Aupdate
BaddObserver
DregisterObserver
Attempts:
3 left
💡 Hint
Common Mistakes
Using different method names for update in interface and notify call.
Confusing addObserver with registerObserver.