Discussion Forum : Understanding the Solution

Discussion Forum : Understanding the Solution

Now I will show you the class diagram which explains how implicit referencing is used to enable discussion forums.

The figure below shows the class diagram.

Figure- Figure

As shown there are two classes Subscriber and Topic. As we know a subscriber should have a common interface using which the subscriber can be notified about the changes. In this case subscriber should have an email id or a method haveEmailID(). We also know for every topic , we will need to have a mediator and hence we can notice a bi directional communication.

In the topic class there are three methods ..

  • subscribe(email id) which takes an email id as an argument
  • unsubscribe(email id) which takes an email id as an argument
  • notify()

The implementation of subcribe method is just three lines of code, whatever email id is passed to the method, blindly add it to the collection.

Subscribe(String emailid)

The implementation of unsubscribe method is again three lines of code, whatever email id is passed to this method, blindly add it to the collection

UnSubscribe(String emailid)

The implementation of notify method is again three lines of code, what ever email ids are there in the collection, blindly send a email to each one of them.

For(all email ids in the collection)
Blindly send the email to all the email ids in the collection.

So we can notice just by having 3 lines of code in each of the methods , the mediator can communicate with millions of colleagues without explicitly knowing each one of them.

So once a person has a valid email id for every topic that he finds interesting the moment clicks on the subscribe button the subcribe() of the topic is called passing the email Id as an argument wherein the passed email id is blindly added to the collection. From this moment, every time the state of the topic changes, the notify method is triggered wherein the emails are send to all the emailids in the collection. This will continue till one decides to unsubscribe. Within every email received for a particular subject, there is usually a link at the end of the email which says “If you don’t want any further messages on this topic click on this link”. In reality the moment a person clicks on this link the unsubscribe() of the topic is called and the email is removed from the collection. Once the emailid is removed from the collection , the subsequent time the notify is called the person will not get a message from that topic. This is how discussion forum functions.

We are currently discussing the observer design pattern which is nothing but a specialized mediator which is flexible wrt varying number of colleagues using implicit referencing as a technique.

Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer