Complete the code to show how behavioral patterns focus on {{BLANK_1}}.
class Observer: def update(self, [1]): pass
Behavioral patterns define how objects communicate by changing their state and notifying others.
Complete the code to illustrate object interaction in behavioral patterns.
class Subject: def __init__(self): self.observers = [] def attach(self, observer): self.observers.[1](observer)
Objects interact by adding observers to a list using append to notify them later.
Fix the error in the code that manages object interaction.
class Command: def execute(self): [1]
The base Command class defines an empty execute method using pass to be overridden by subclasses.
Fill both blanks to complete the interaction between objects in the Chain of Responsibility pattern.
class Handler: def __init__(self, successor=None): self.successor = [1] def handle(self, request): if self.can_handle(request): self.process(request) else: if self.successor is not [2]: self.successor.handle(request)
The handler stores the next handler as successor and checks if it is not None before passing the request.
Fill all three blanks to complete the Mediator pattern example showing object interaction.
class Mediator: def notify(self, sender, event): if event == [1]: self.colleague1.[2]() elif event == [3]: self.colleague2.action()
The mediator reacts to "event1" by calling respond on colleague1 and to "event2" by calling action() on colleague2.
