Complete the code to define the Observer interface method name.
class Observer: def [1](self, message): pass
The Observer pattern requires an update method that observers implement to receive notifications.
Complete the code to select the correct Strategy interface method name.
class Strategy: def [1](self, data): pass
In the Strategy pattern, the method that performs the algorithm is usually called execute.
Fix the error in the Command pattern method name for executing a command.
class Command: def [1](self): pass
The Command pattern uses an execute method to perform the action.
Fill both blanks to complete the Observer pattern subject notifying observers.
class Subject: def __init__(self): self.observers = [] def attach(self, observer): self.observers.append(observer) def notify_observers(self, message): for observer in self.observers: observer.[1](message) subject = Subject() subject.[2](observer_instance)
The Subject calls update on each observer to notify them. To add an observer, it uses attach.
Fill all three blanks to complete a Strategy pattern example selecting and running a strategy.
class Context: def __init__(self, strategy): self.strategy = strategy def set_strategy(self, [1]): self.strategy = [2] def execute_strategy(self, data): return self.strategy.[3](data)
The Context sets a new strategy using the parameter named 'strategy'. It then calls the strategy's execute method to run the algorithm.