MVP design pattern in android simplified

Swanand Keskar
1 min readMay 21, 2017

--

MVP Design pattern stands for Model-View-Presenter . It decouples the code so that business logic and view can be separated so that we can unit test the code easily at the same time making it maintainable.

Model : it represent the data from api , sqlite or any other local database ,we can perform filtering of data inside this layer.

View : it consists of activity ,fragments ,adapters which handles the user interaction and anything that runs on UI thread.

Presenter : it is the class which co-ordinates between model and view.

How it works ?

The user interaction is performed on the view .view delegates it to the presenter .Presenter then gets the data from the model and updates the view.It provides separation of concerns as view never directly interacts with the model.

Lets go through code :

Above the mainactivity interacts with the abstract concept MainView. On the click of button the event is delegated to the presenter.

The presenter then updates the view by invoking the openNewWindow() method of the MainView

this example shows how the events are delegated as per MVP architecture

Link: Twitter , Github

--

--

Swanand Keskar

Solutionizer | Fullstack Dev | Google Certified #Android Developer swanandkeskar.com