publish-subscribe pattern class subscriber(object)def process(selfobserved)print("observing{}format(observed)class publisher(object)def __init__(self)self subscribers set(def subscribe(selfsubscriber)self subscribers add(subscriberdef unsubscribe(selfsubscriber)self subscribers discard(subscriberdef unsubscribe_all(self)self subscribers set(def publish(self)for subscriber in self subscriberssubscriber process(selfnow it is clear that we are dealing with two classesone that deals with publishing and another focused completely on processing something in the code snippetit is not yet clear what should be published and what should be processed we proceed in our attempt to clear up any uncertainty in our model definition by adding message class that could be published and processed class message(object)def __init__(self)self payload none class subscriber(object)def process(selfmessage)print("message{}format(message payload)