Publish/subscribe (or pub/sub) is an asynchronous messaging paradigm where senders (publishers) of messages are not programmed to send their messages to specific receivers (subscribers). Rather, published messages are characterized into classes, without knowledge of what (if any) subscribers there may be. Subscribers express interest in one or more classes, and only receive messages that are of interest, without knowledge of what (if any) publishers there are. This decoupling of publishers and subscribers can allow for greater scalability and a more dynamic network topology.
Much the same way, the publisher can only notify subscribers it knows about. There is no way for the publisher to deliver an event to whomever wishes to receive it, nor is there an ability to broadcast an event. In addition, all publishers must repeatedly have the necessary code to manage the list of the subscribers and the publishing act itself.
There is no way for a subscriber to ask that if an event is fired, the application should create an instance of the subscriber and let it handle the event.
Setting up subscriptions has to be done programmatically.
Each entry in the dictionary contains the name of the topic and all its subscribers in the form of a linked list.
Each linked list contains the list of subscribers for a particular topic.
For Example a pub/sub scenario is given in Figure 2 and its equivalent data structure is given in Figure 3.

Algorithm:
Decouple the publishers from the subscribers by introducing a dedicated subscription service and a dedicated publishing service

Subscribers that want to subscribe to events will register with the subscription service.
Subscription service will manages the lists of subscribers in topic basis as shown in the data structure.
When there is an event of a particular topic in publishing service.
The publishing service will want subscriber list from subscription service for the particular topic.
Then publishing service will send the event to each subscriber of the list.









Figure 9: Coupling Between Objects
Fgure 10: Depth in Tree (DIT) 

