Observer Pubsub EventListener - MilanVlaski/hexa-draw GitHub Wiki
Listener over other names
The Observer pattern is a way to avoid direct communication between a Model and others who should know about the state of that Model. Usually, these are Views, but sometimes they can be other Models. It may also be called Publisher/Subscriber.
A much more common name, on the web, or on Swing, is the EventListener, or Listener, for short. I (MV) think the popularity of this abstraction and naming pattern is due to it being more understandable than Subscriber or Observer. Therefore, we should adopt the convention that wherever we have this loosely coupled communication, we use the term ThingListener where Thing is the thing being listened to, or the event being broadcast.
- Another benefit is that Thing doesn't have to change it's name
- We can also make it Listeners, plural, if we want to introduce many of them
- If the Thing being listened to, is not a thing at all, but an event, then the Listener can be called EventNameListener, with methods taking the EventName as an argument
How it ties into MVC
In typical MVC, if the View is a Listener, then the controller becomes less important. Because the Model talks somewhat directly to the View, but behind a Listener interface. The need for a controller stems from a Model containig only data. Then, the Controller must query the data, and inject it into the View. If the Model has a Listener, the controller is not as important anymore.