Complete the code to define a method that triggers notification on state change.
def notify_on_state_change(self, new_state): if new_state != self.current_state: self.current_state = new_state self.[1]()
The method send_notification is called to notify when the state changes.
Complete the code to register an observer for state changes.
def register_observer(self, observer): self.[1].append(observer)
The list observers holds all registered observers to notify on state changes.
Fix the error in notifying all observers about the state change.
def notify_all(self): for observer in self.[1]: observer.update(self.current_state)
The method iterates over observers to call their update method with the new state.
Fill both blanks to create a dictionary mapping states to notification messages.
state_messages = {
'active': '[1]',
'inactive': '[2]'
}The dictionary maps each state to a clear notification message.
Fill all three blanks to implement a method that sends notifications with proper message and logs the event.
def send_notification(self, message): self.notification_service.[1](message) self.logger.[2](f"Notification sent: [3]")
The notification service send method sends the message, and the logger info method logs the message content.