Listener is usually a type of interface implemented by object classes that respond to certain actions. If you have an Onfilecontentchangedlistener interface, for example, it will declare a method called Onfilecontentchanged. Anyone who wants to respond to file change events must be from a class that implements this interface. But that’s probably not gonna be enough. It is necessary to register these objects as listeners of the event with the object that realizes that such an event occurred. An example, in the case of Android, is when you do the.setOnClickListener(youListener), where youListener is an example of a class that implements Onclicklistener. What will happen is that the button, when receiving from the user interface manager a signal that there was a click on it, it will search in its internal list of listeners interested in knowing that there was a click and call the Onclick method from each of them.
As you can see, there is no magic: someone has to call his method. In the case of Onfilecontentchangedlistener, there will have to be an object that records file change listeners. This object will have to have some way of knowing when there was a change in the file to call the Onfilecontentchanged methods of the registered listeners. This may or may not be done by Polling (staying all the time going there and checking the modification date, for example). Even if it is, it’s still much better than every object interested to stay making your own Polling. In the real world, many events of this kind work via signals, because Polling is not very efficient.
In short: your Istener will not stand by and wait. He will register as a listener and move on with his life. Who will be responsible for warning when the time comes is the "observer". On how to implement a file observer, check the implementations of the Watchservice interface (Java 7). If you need more information, add it when you’re on PC.
Got it. Thanks a lot for your help. :)
– Lucas Schneider