What is the advantage of the MVP pattern (GWT)

我是研究僧i 提交于 2019-12-03 17:01:28
topchef

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)

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.

The fact of not using the GWTTestCase is pretty awesome especially if you do test driven development but there are other great benefits like topchef mentioned. It kind of depends on which "version" of MVP you go with. I cringe when I see people registering the Presenter as a listener to widgets that are exposed from the view.

One of the issues that surround MVP in general is there are several flavors and people new to the pattern get confused because each flavor has differing advantages and disadvantages. You can take a look at these two articles to help with deciding if it is for you and get more details about MVP (along with other things you might get mixed up with it): GWT MVP Pattern and GWT MVP, Activities and Places Confusion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!