Android SDK is majorly all about its relation between the data, activity, and overall backend layout, once we analyze we observe Android comes with MVP, MVC, MVVM and so on, and each community claims that their pattern is best suitable for application development. But when it comes to more complex projects the realization of unit tests isn’t efficiently handled by MVC (Model View Controller) or MVVM (Model-view-view Model).
Android SDK, having the ability to allow other patterns as well, hence we take advantage of a better architecture which is Model View Presenter (MVP) that is more efficient when we talk about separation of concerns and offer some other advantages that MVC lack.
The Model holds the business logic of the application. It manages how data is shaped, storage of data, and how the data is modified. The View is a passive interface that displays data and routes user actions to the Presenter. The Presenter acts as the middleman. It retrieves data from the Model and shows it in the View. It also processes user actions forwarded by the View.
Models like MVC, MVP, and MVVM all are feature rich and give a good list of advantages, hence each of it has a number of supporters.
So, the correct answer to this question is not one, basically, it depends on the nature of application you desire to develop, so let us look at the pros and cons of both architectures to decide upon which architecture to prefer according to your application, also look for the difference between MVC and MVP architectures.
MVP makes views independent from our data source. We divide the application into at least three different layers, which let us test them independently. With MVP we are able to take most of the logic out of the activities so that we can test it without using instrumentation tests.
Android applications have activities that are inter-correlated with the view or User Interface and data access techniques. For an application with the capability of feature-enhancement and update and timely maintenance, we need well defined and separated layers, which give an ease of unit testing, so that updating the application gets easier.
The MVP pattern is more flexible when it comes to assigning activities and responsibilities to different layers, this flexibility often converts into a confusion, suppose the decision of making a layer responsible for the enabling and disabling of the progress bar, here most developers might get confused between presenter and view layer. At a point, it all comes to the decision you make in order to implement MVP in a productive way. Let’s have a look layer by layer to identify what is the best way to implement MVP.
Presenter works as a middle man between the model and view layer. It is responsible for extracting data from the model layer and passes on its modified version to the view layer. Additionally, it is responsible for the decision of taking an action each time the user interacts with the view layer.
The view invokes the presenter layer each time User interacts with the application, and the presenter layer as mentioned above decides which action to be taking depending on the action of the user, ideally for each action the dependency injector such as dagger is provided to the presenter. So the only thing view does is passing on the user action to the presenter and receives (from the presenter) the re-action to be displayed to the user.
Model is the storage of all data you can say when the presenter finally decides the action to be taken in answer to the user-action, it calls the model for the corresponding data to be displayed by view layer. In an ideally layered architecture, Model is a mere gateway to the data and business logic stuff.
The Model View Presenter prevents our application to be coupled and overlapped by number of layers and classes, so the maintenance and feature enhancement becomes easier and more likely adoptable, so especially in large applications it is crucial to keep the layers separated and update the application as per users’ feedback, hence MVP is a preferable architecture when it comes to bigger and more complex applications.
Learn Android MVP online with Udemy by looking through practical examples. Create modules, and implement the whole MVP including the View, Model, and Presenter. Not only this also learn handling configurations and much more.