LLD - Behavioral Design Patterns — Part 1
Given the following pseudo-code implementing a behavioral pattern, what is the output?
class Publisher:
def __init__(self):
self.subscribers = []
def subscribe(self, sub):
self.subscribers.append(sub)
def notify(self, msg):
for sub in self.subscribers:
sub.update(msg)
class Subscriber:
def __init__(self, name):
self.name = name
def update(self, msg):
print(f"{self.name} received {msg}")
p = Publisher()
s1 = Subscriber("A")
s2 = Subscriber("B")
p.subscribe(s1)
p.subscribe(s2)
p.notify("Hello")