I have been looking at this tutorial
https://developers.google.com/web-toolkit/articles/mvp-architecture
What I was wondered is with this MVP style how efficient is it that every time a user changes page that it goes and creates a new instance of the Presenter. Would the presenters be better if they were singletons? My end goal is to deploy an app using PhoneGap so any performance gains would be useful.
I have been looking at this tutorial https://developers.google.com/web-toolkit/articles/mvp-architecture What I was wondered is with
Share
It all depends on your implementation.
If you want the state to be saved on your view you could go with a singleton presenter/view.
It is more efficient, as you do not need to re init the view but less efficient if some transaction on another view makes a change that will need to change the first view. In this case you need to raise an event in the second presenter that is caught on the first presenter and modifies the view accordingly. This makes the application a little less predictable.
So if each presenter/view is independent a single view/presenter would be the thing to do.
In any other case I would go with a new presenter/view to re-initialize the data in the forms the view uses.
Bear in mind though that each new presenter that uses application wide variables (such as an event bus) would not be destroyed (garbage-collected) which would lead to the following problem:
Any time you load a View and an event is raised that is caught in the corresponding presenter, the event and all the calculations will occur as many times as a new presenter/view is generated.
Example:
-Presenter1/View1 is loaded and catches some event
-Presenter2/View2 is loaded
-Presenter1(new instance)/View1(new instance) is loaded and catches some event.
-Event is raised via the global event bus
-Presenter1 catches the event
-Presenter1(new instance) catches the event
So in essence (that is not a rule) a new presenter gives the GWT application a web-page with full postback feeling, and in the other case you have the Desktop application feeling that loads already existing forms.
Hope this helps.