Naming methods in presenter
Suppose you want to exit you application when user press back button.
In your View (activity) you can have this code
@Override
public
void
onBackPressed()
{
presenter.exitApplication();
}
On first sight, it seems everything is fine with this code.
Now look at your presenter exitApplication() code:
public
void
exitApplication()
{
MyApplication.getInstance().exitApplication();
}
Now, looking at this code, you can ask yourself why and when View decided to call this method? Looks that Presenter is here only to forward some method calls.
Now you must to inspect View code!
As you can see, responsibility for "what to do onBack", is actually in View vode, just because the method in presenter is called exitApplication().
Methods on presenters should map to user actions or events, so presenter can choose what to do depending on user action.
In our example, better way is to have presenter.onBackPressed method, and let presenter choose what to do when user press back button.
This way you will not need to inspect View (activity) code wondering why some presenter code is called.
So better code would be:
View code:
@Override
public
void
onBackPressed()
{
presenter.onBackPressed();
}
Presenter code:
public
void
onBackPressed()
{
MyApplication.getInstance().exitApplication();
}