FuzzDuck
FuzzDuck
Observer pattern
FuzzDuck
Observer pattern

Observer pattern

The Observer Pattern consist of two core classes. One is the Subject, the other is the Observer. The Subject holds information, variables, which is shared with observers subscribing to receive theese informations. The observers may chose to stop receiving messages by being removed from the Subjects subscribing list. If compared to real life examples, the pattern shows resembles to a newspaper company, delivering news. People may choose to subscribe to the news, just like Observers may choose to subscribe to the Subject’s information.

Observer Pattern UML

The publisher and subscribers

Image a magazine publisher, publishing a new edition of magazine each month. A lot of people want theese magazine delivered to their homes, so they chose to subscribe. They call the publisher, which include these subscriber in their system and delivers a new magazine each month. If the subscribers chose to unsubscribe they call the publisher and are removed from the subscribing list. Each month a new edition of the magazine gets published, and the subscribers gets updated, receiving the new magazine.

Observer pattern - Publisher and subscriber UML