Observer Design Pattern

Observer Pattern is design Pattern which describes one to many relationship, which helps in publisher-subscriber model, where one publisher can notify to multiple subscribers.
Usually one or more subscriber classes will be there for this pattern, and these classes will be notified based on the publisher notification change.

Java Swing listeners are part of an Observer design pattern implementation.
As listener is an implementation of Observer Pattern, as it is triggered by an event.

Below is a simple example of multiple RSSFeed Subscribers and a single RSS Feed News Publisher. (Using Observer & Observable Pattern already present in Java)

The publisher publishes news like entertainment, political & sports news one by one, and the RSSFeed subscribers(observers) are getting their news changed., accordingly.

  Output:

Leave a Reply

Your email address will not be published. Required fields are marked *