I am learning GWT and i have read at multiple places that using MVP architecture is best suitable to develop a GWT Application
I have also read that its easy to do testing using the MVP ARCH.Can somebody explain me why its easy to do testing using the MVP architecture.
Also i am working on a project using MVP and i find it very tedious to make the view connect to the data base.I mean i have to update my presenter,service,serviceAsync,servicImpl,Facades in order to make connection to database.
So can somebody provide me the essence of MVP for GWT?i would appreciate a couple of examples.
Separation between the presenter (which contains logic) and view (a dumb wrapper around UI controls) allows you to:
The latter use case is rare, so let’s focus on the MVP model’s suitability for automated, programmatic testing. With a team of developers this often takes the form of a continuous build/test cycle using Hudson (or similar) on a headless server, where it’s not practical to open a web browser, create controls, etc. every time a test is run.
Typical usage of MVP+GWT is that views implement an interface provided by the presenter, and often this interface is defined in terms of other generic interfaces. Here’s a very simple presenter that increments a numeric label when a button is clicked – note that instead of exposing the TextBox and Button directly, the view returns generic HasText and HasClickHandlers instances:
The “real” view returns UI widgets (created via UiBinder in this example):
whereas unit tests create a dummy implementation (or use Mockito, EasyMock, etc.) and thus don’t require any UI components:
As for your next paragraph: your views shouldn’t be connecting to the database at all! The presenter should request data via Service/ServiceAsync (or an abstraction such as gwt-dispatch or gwt-platform), then call methods on the view to populate the UI.
By the way, those last two links (along with gwt-presenter) are a good start if you’re looking for GWT MVP code samples – combined with Google GIN they provide frameworks for tying all this stuff together.
Having said all that, I agree – the combination of GWT+MVP+Java can be hard work and extremely verbose (I’m glad I don’t have to work with it much these days). The alternative, though, is even less attractive: an untestable, unmaintainable ball of spaghetti…