GWT, MVP and Eventbus

I have been using GWT and MVP for 2 years and so. I loved the way MVP provides flexibility of working with multiple views. In GWT or Swing based application design muddles very quickly.  Maintenance becomes nightmare. We don’t think about the separation of concern, then mix up the UI code and business logic together.

MVP (Model View Presenter) proposes following things -
·    View is an interface which is a contract for presenter. here you can define the operations and expose widgets that will be present in the UI. for example if an UI needs an input box for user name and  a  button then you can expose two methods getName() and getOkButton().  Get name can be implemented using whatever widget user wants- a textbox or a custom widget.
·    View implementaion implements the view interface and only concentrate on layout or grouping of widgets. Doesn't perform and logic, doesnt attach any DOM handler to any widget. If any widget needs to be attached to a handler (e.g. if Ok button is clicked then need to perform some logic) then the widget needs to be exposed in view interface.
·    View should not know about Model or DTO. Data should be transferred from presenter to View using primitive or wrapper data type. e.g. List<String> userFirstNameList.
·    Presenter knows about the view interface, when a presenter is created then an instance of View is passed to the presenter. Presenter doesn’t know anything about view Impl.
·    Presenter adds handlers to the exposed widgets and performs business logic. 
·    View should not expose low level widgets like Button or Checkbox; instead it should expose higher level interface type- e.g. HasClickHandlers. So that Presenter doesn’t have to know anything about GWT framework specific and easily JRE tests can be written.
·    Presenter performs the business logic and View provides user interface.
·    Model is raw data in DTO format.
·    When Model changes then Presenter handles the View transition. Either method of view is called with changed data or presenter notifies that I am done somebody needs to handle it next.
·    Then another presenter does that. This transition handled using History management of GWT
·    So, View, Presenter and model are no longer tightly coupled. Junits can be written easily for the business logic. if Model changes then view doesn’t have to change- Open close principle is followed.
GWT provides ways to write custom events. Developers get confused about what is DOM and what is GWT event.
DOM events are UI events associated with Widgets. Business events are logic that needs to be performed on DOM events.
Not all DOM events are business events.  For example - If you are developing a social networking register user functionality and in UI you have country dropdown, state dropdown and Save button. Here when user changes country dropdown then if country is not US then state needs to be disabled, this is not business event- this is UI functionality user should not be allowed to choose a state if country index is 11.  But when user hits save then you perform validation and then make service call. This is business event.

I will post a GWT, History, MVP and event bus example soon

Comments

  1. Clearly explained.
    Will be waiting for the GWT, History, MVP and event bus example. Thanks.

    ReplyDelete

Post a Comment

Popular posts from this blog

NSSM service eats 100% CPU

JPA Vs SpringJDBC

Ignite Running in Static IP multicast mode