MVP Pattern Android ?


In large applications, it’s essential to organize your code very well. MVP allows you to separate business logic from presentation layer. MVP makes views independent from our data source. In Android, activities and data mechanism will be tightly coupled . With MVP we are able to take most of logic out from the activities so that we can test it without using instrumentation tests.

mvp

Presenter:

Presenter contains the UI business logic for the View and a middle man that talks to the View and the Model. The Presenter is also decoupled directly from the View and talks to it through an interface, this is to allow mocking of the View in a unit test.

View :

This view will implemented by Activity or Fragment will contain the reference to Presenter.

Model:

This is provider of the data we want to display in the view.

Implement MVP pattern:

1. Creating an presenter interface

2. Implementation for presenter – As UI logic will be implemented in this PresenterImpl.

3. Create an view interface- where activities or fragements implements this interface

 

References:

1. http://antonioleiva.com/mvp-android/

 

Advertisements