user1119283
user1119283

Reputation: 431

MVP in terms of UI and View

What does the following mean?

GOALS in GWT Develeopment

We need dumb Views, not dumb UIs (What does View mean here and whats UI in MVP ? its confusing, please explain with a small example, a simple one)

• Avoid state within Views (Which state is it talking about, please explain with a small example, a simple one)

• Swap out Views for different platforms (What is the swapping thing here? does he means change of different technology, say from GWT to Flex )

Please explain using a simple example :)

Thanks

Upvotes: 1

Views: 328

Answers (2)

Ümit
Ümit

Reputation: 17489

  1. Well I assume it means that you should try to avoid having complex business logic and model states in your Views. The reason why people advocate to keep the views in GWT as dumb as possible is that views have widget related code and whenever you try to test widget related code in GWT you have to fall back to the slow GWTTestCase and not the fast JUnit tests.
    In TDD (Test Driven Development) you heavily rely on tests and in order to allow for efficient development these tests should run fast.
    So what you try to do in GWT is to keep the Views as dumb as possible so they don't require a lot of tests (maybe just integration tests at the end) and to put all business related code in your Presenters. The Presenter should have no widget related code and should handle model states. Then you can use the fast JUnit tests to completely cover your business logic code in the Presenters. See here and here for more details.

  2. Swapping out views for different platforms refers to having different view implementations for different devices for example. It makes sense to have different layouts for a mail application when viewed from different devices.
    On a tablet where you have enough screen size you might have a list of mails on the left side and the actual mail content in the center part. However on a phone you will probably only display the mail-list and when you click on a mail the view will be changed to the content of the mail.
    The business logic for the mail application is independent of the layout/view. So you try to put this code in the Presenter and design your Views in a way that they can be easily swapped out based on the user-agent for example. You can check out the mobilewebapp sample app in the GWT repository and this I/O conference talk.

Upvotes: 2

ramon_salla
ramon_salla

Reputation: 1607

some thoughts I learned recently about MVP Widgets, they could not be theorically exact, but they are ok for me and the team I am working with.

  1. In MVP there is only one V concept. Avoid V vs UI in MVP, they are the same concept. (UiBinder has nothing to do with MVP, but you can use UiBinder to build your V for your MVP Widget).
  2. The Model is your data and should be only modified inside your P.
  3. The V is the screen of this data and should never change it.
  4. The P handles the data, the behaviour of your widget, the events to other widgets and the services (RPC, Rest...).
  5. Avoid keep instances of your data in your V.
  6. V and P communicate each other with handlers. There are two ways of doing this. A) Handling the View events directly on the P (let V implement an interface defined in P) or B) passing P reference to the View. Let P and V implement interfaces as a contract. I recommend A.
  7. Some Data is generated in V (TextArea, Combos...) and eventually become part of your Model. Just try to keep their changes in P (as explained in 6).
  8. P1 and P2 and P3 and... communicate each other via EventBus.
  9. Let your P implement IsWidget this will allow you to instantiate a MVP Widget in another Widget's V. (Nested Widgets). This will also allow you to break big MVP into littles MVP widgets (easy to mantain, easy to keep track with different developers ...).
  10. Doing the 6A) it is easy to JAVA test your widget behaviour (your P) only mocking the view.
  11. Test your V with selenium or others.
  12. Doing the 6A) different V can implement P inner interface. One for mobile, another fo r PC... This is easier to say than to do.

That's all, hope this helps you.

Upvotes: 1

Related Questions