On Monday, January 16, 2012 4:05:01 AM UTC+1, Qrunk wrote:
Hi Thomas,
As you asked, I went through the link(http://www.google.com/events/io/2010/sessions/gwt-continuous-build-testing.html)
but there it was a bit difficult for me to understand the basic reason as to why
1. we shouldn't use view.getSaveButton().addClickHandler().... i.e to say why we should not have getter in our Display interface??
If you want to test your presenter, you'll create a mock view. With a getSaveButton, you have to mock a HasClickHandlers in addition to the view. The mock will record the added ClickHandler-s, and should return HandlerRegistration to allow unregistering them. Finally, to simulate a click, you might need to mock a ClickEvent too (you could pass 'null' as the event if you know the presenter isn't going to extract any information from the event). This is a lot of boilerplate for a single button.
If you instead have a onSave() or save() or doSave() on your Presenter interface (that the view calls back), mocking the view and simulating the "click" becomes much easier.
What I understood from the video is that it is not a good practice to maintain views state information within the presentation, but sorry to say I didn't understood how is that gonna help us. ?
This is another aspect of how Wave implemented MVP: the presenter maintains the state, and pushes it to the view; not the other way around. Again, this makes mocking and testing easier. For instance, instead of having your values "stored" in your view's fields (TextBox for instance), you'll store them in (Java) fields in the presenter. You'll push the value to the view each time you detect it changes, and the view will pass it back to the presenter as an argument to the callback method.
This doesn't work very well with data-heavy screens (e.g. when you have half a dozen form fields or more) though, but it works very well with small reusable widgets (Wave uses it for buttons for instance, where their buttons' views are not simply Button widgets, and where the "state" stored in the presenter is whether the button is enabled/disabled, its text, whether it's pressed/released)
2. In that video its also mentioned that we should use setListeners() rather than addListeners(), that is to avoid more than one listener in the interface.
Again, makes things simpler; and you'll actually never have 2 listeners (2 presenters) at the same time, so.
3. He says he is diverging from Rays understanding of MVP, with respect to not using HasClickHandlers() , please explain why ?
See above.