What is the advantage of the MVP pattern (GWT)
Asked Answered
C

2

5

I just read this article and it did confuse me a lot.

Secondly, this model allows us to minimize our use of GWTTestCase, which relies on the presence of a browser, and, for the bulk of our code, write lightweight (and fast) JRE tests (which don't require a browser). [1]

Is this the whole benefit, I have from following this design pattern? It seems to make the code more complex... Do you use this pattern?

Cretic answered 6/3, 2011 at 16:50 Comment(4)
As a note, I found GWT's own MVP implementation annoying to work with. I suggest GWTP code.google.com/p/gwt-platform, which provides a very good base for all of this using dependency injection, and also gives you automatic code splitting.Beacon
Thanks, I will have a look at GWTP.Cretic
Although I started to use GWTP which is nice, for sake of completeness (but not exhaustiveness!), I want to mention MVP4G (not to confuse with MVP4J!), which has a nice comparison of design with GWTP (with (polite!) comments from GWTP's author...).Incomputable
Well, there are indeed more MVP frameworks than I thought: #4399710 but GWTP and MVP4G seems among the most popular (without hard evidence, just my feeling).Incomputable
S
8

I have to disagree, MVP makes code way less complex, especially in case of GWT. If you plan on medium to large size GWT project then MVP architecture is your primary option. I suggest to look at both GWT MVP (by Google) and at gwt-platform (suggested by KennethJ). There are other implementations as well.

MVP's main benefits (I mean MVP pattern - not just GWT MVP):

  • clear separation of GWT UI and business logic; all your client side Java code becomes extremely generic with minimal dependency on GWT implementation (primarily via interfaces). This helps tests tremendously but it's invaluable benefit of UI design by itself.
  • maintainability of UI increases due to almost no dependency on business logic
  • increases amount of shared code between client and server due to limited GWT dependencies

Other complementing technologies that you are likely to adopt:

  • gwt-gin (client side implementation of Google Guice): gwtp makes it almost required (or required - I never tried without it)
  • Guice (server side) for consistency with client code but not necessary technically
  • test mocking framework (e.g. mockito) always comes handy with MVP
  • GWT UIBinder - unless you are extremely dynamic in your UI design
  • GWT EventBus - main method of client side communication in asynchronous environment like AJAX/JavaScript
  • GWT-RPC via command pattern (gwtp dispatcher and/or RequestFactory)
Solano answered 7/3, 2011 at 16:40 Comment(0)
H
0

advantage compared to what? if you mean advantage compared to standard MVC pattern (the common pattern for UI development), then yes, I guess that's the main reason for this pattern

GWTTestCases are far slower and cumbersome than standard junit tests. You'd want to test the logic using standard java testing frameworks and use GWTTestCase to test only UI specific logic.

Henryk answered 6/3, 2011 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.