4 ms·
MVP _is_ huge (probably de-facto pattern) in the Google WebToolkit community. The way I see it is this: MVC works for Widget level (imagine a Swing component:
by edwinnathaniel 11y ago
MVP _is_ huge (probably de-facto pattern) in the Google WebToolkit community.
The way I see it is this: MVC works for Widget level (imagine a Swing component: JTable or something, there's the table rendering => View, the table data => Model, the table event processing/logic => Controller). But you need a higher-level architecture that controls everything in the app and that's where MVP comes in.
There's no framework per-se in GWT because MVP is so easy to implement.
View v = new ViewImpl(); // usually View is an interface or you can mock it...
Service s = new ServiceImpl(); // usually Service is an interface, or you can mock it...
Presenter p = new Presenter(service, view, models);
// in constructor
v.addListener(new Listener(){ public void execute(){ p.processData(); };});
p.getData(); // potentially calls service ajax request
p.persist(); // calls s.persist(model);
p.processData(); // potentially called by the event listener from the view, say user press a button
The idea of MVP is to be able to write unit-test (against the Presenter) that does not touch the widget level but able to cover everything else. Attaching a listener to ensure a code will be executed is considered "configuration".
This MVP style differs to the one mentioned in the Ezra blog where the model calls Repository/Service. This MVP styles makes it explicit for Presenter to orchestrate the Model, View, and Service interaction. No two way binding or implicit stuff.