I tried to implement this factory method and use maps (one for
presenters, views and services, as described before) to delay
instantiation of the presenter and the bind of the view. I've been
disappointed by the result since performances were not as good as
before.
Also stocking presenters in a map means that the more presenters you
have, the longer it will take to retrieve a presenter from the map and
treat an event.
So I want to try another approach, closer to the GWT lazy panel.
Like lazy panel, presenter will be instantiated at the start but they
will neither be built nor bind to the view before they have to handle
an event. I want to introduce a new method in presenter definition:
bindIfNeeded. This method will be called all the times before the
presenter has to handle an event to verify that the presenter was
binded to view. If it's not the case, the bind method will be called,
otherwise nothing will be done. Like that, the framework will call the
bind method only when needed and it will make sure to call this method
only once. Thus developers can build the presenter and its view in the
bind method. The bindIfNeeded method will be implemented by
BasePresenter so developers won't have to worry about it.
View and presenter will be instantiated at the start but not built
until they have to handle their first event so you can speed up start
up time.
Developers will also be able to decide if views and presenter should
be built at the start or when they handle their first event.
You would have something like:
public Mvp4gStarterImpl implements Mvp4gStarter{
public void start(){
LoginView loginPresenterView = new LoginView();
final LoginPresenter presenter_LoginPresenter = new
LoginPresenter();
...
AbstractEventBus eventBus = new AbstractEventBus(){
public void init(){
checkBind(presenter_LoginPresenter).onInit();
...
}
...
}
}
public <T extends PresenterInterface> T checkBind(T presenter){
presenter.bindIfNeeded();
return presenter;
}
...
}
public BasePresenter<T,V> implements PresenterInterface<T,V>{
private boolean binded = false;
public void bindIfNeeded(){
if(!binded){
bind();
binded = true;
}
}
}
public LoginPresenter extends BasePresenter{
public void bind(){
//build presenter
buildPresenter();
//build view
buildView();
//bind view
...
}
}
This shouldn't impact performances that much and be more scalable.
What do you think?
-Pierre
> > -Pierre- Hide quoted text -