The Observer pattern in the real world
We will take up a news agency case to demonstrate the real-world scenario for the Observer pattern. News agencies typically gather news from various locations and publish them to the subscribers. Let's look at the design considerations for this use case.
With information being sent/received in real time, a news agency should be able to publish the news as soon as possible to its subscribers. Additionally, because of the advancements in the technology industry, it's not just the newspapers, but also the subscribers that can be of different types such as an e-mail, mobile, SMS, or voice call. We should also be able to add any other type of subscriber in the future and budgeting for any new technology.
Let's develop an application in Python v3.5 and implement the preceding use case. We will start with the Subject, which is the news publisher:
Subject behavior is represented by the
NewsPublisher
classNewsPublisher
provides you with an interface so that subscribers...