Hi all, I am new to GWT and I am looking into MVP1 architecture. I am learning from GWT documentation. I am going though the Contacts application.
I understood the flow and the need of having Presenter, View and AppController. But the thing which I dint understood is what is the need for having the Event classes and EventHandler classes under com.google.gwt.sample.contacts.client.event package?
For instance we can consider this code snippet from ContactsPresenter.javaWhen I click on Add button, new AddContactEvent() is being initialized. Already we binded this event with a event handler in AppController like thisthen addNewContact() method is called in which we are simply changing the History like thisWhat I don't understand is instead of writing all this code I can simply change the history from presenter method itself like thisWhy Should I use events and handlers approach instead?
On asking to one of my friends, he said that some times we might want to do some initialization before the view is actually loaded, there is a common central place(AppContoller) for every presenter to communicate. But I am not convinced with the answer.
Can anyone please shed some light and make it clear.
Hi all, I think I understood why we need to use an XXXEvent class and XXXEventHandler class. I'll put my understanding and anyone please tell me whether I am right or not.
I understood that if at all I want to change the view from a Presenter I have to use event bus and fire an event, this initializes a handler which is written in AppContoller.
Firing events is only used when we have to change the view from a Presenter. We can directly change the History from Presenter as I discussed in this post, but the point is if we want to execute some business logic each time a particular view is loaded, then in each Presenter I have to write the same code. This is a repetitive process.
Having event bus and firing the event will initialize the handler written in some central place, in our case it is the AppController. Now I can simply write the business logic in a method in AppController class and call it each time the handler is invoked.
This is what I understood after writing a sample application on my own and after discussing with friends.