0
0
LLDsystem_design~10 mins

Notification on state change 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 define a method that triggers notification on state change.

LLD
def notify_on_state_change(self, new_state):
    if new_state != self.current_state:
        self.current_state = new_state
        self.[1]()
Drag options to blanks, or click blank then click option'
Alog_change
Bupdate_state
Csend_notification
Dreset_state
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a method that only updates state without notifying.
Using a logging method instead of notification.
2fill in blank
medium

Complete the code to register an observer for state changes.

LLD
def register_observer(self, observer):
    self.[1].append(observer)
Drag options to blanks, or click blank then click option'
Aobservers
Bnotifications
Clisteners
Dsubscribers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that does not store observers.
Using a singular form instead of plural.
3fill in blank
hard

Fix the error in notifying all observers about the state change.

LLD
def notify_all(self):
    for observer in self.[1]:
        observer.update(self.current_state)
Drag options to blanks, or click blank then click option'
Asubscribers
Bobservers
Cnotifications
Dlisteners
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name causing runtime errors.
Using a variable that does not hold observer objects.
4fill in blank
hard

Fill both blanks to create a dictionary mapping states to notification messages.

LLD
state_messages = {
    'active': '[1]',
    'inactive': '[2]'
}
Drag options to blanks, or click blank then click option'
A'User is now active'
B'User is now inactive'
C'State changed to active'
D'State changed to inactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping messages between states.
Using generic messages that do not specify state.
5fill in blank
hard

Fill all three blanks to implement a method that sends notifications with proper message and logs the event.

LLD
def send_notification(self, message):
    self.notification_service.[1](message)
    self.logger.[2](f"Notification sent: [3]")
Drag options to blanks, or click blank then click option'
Asend
Binfo
Cmessage
Dalert
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names causing errors.
Logging wrong variable or missing message content.