- Complications While Updating the database.
- Lack of communication between the data layer and the View layer.
- Time-Consuming Debugging with too many complexities.
- Impossibility to test the business logic, resulting in unexpected errors.
MVP (Model View Presenter)The MVP model is basically an improvement over the conventional MVC model. In this case, the Controller is replaced by the Presenter. The modification was much needed to enhance the functionality of MVC for better coding execution and better UI design. Here’s how the MVP pattern works.
ModelThe Model is responsible for handling the local database interactions. It responds to the queries by fetching or updating the information at the database. It means that if the function being called is requesting certain information from the database, the Model will locate it and respond accordingly. The Model only interacts with the Presenter and doesn’t have any idea about the existence of View at all.
ViewLike Model, the View also interacts with the presenter only to visually display the data to the user. It also notifies the Presenter regarding user inputs. View, however, doesn’t process the data at all. In fact, the View doesn’t directly interact with the Model as well. Its only job is to display the information to the user.
PresenterThe presenter is the layer which acts as a mediator between the other two layers. It interacts with both the Model and the View to transfer the data between two layers. It’s only responsibility is to collect user input and pass it to the Model. The model then processes the data accordingly and passes the result to Presenter again, which is then further passed to View.
Pros and Cons of MVPWhile the MVP model has several improvements over the conventional MVC pattern, it still has pros and cons of its own. Let’s take a look at some of the advantages and disadvantages of MVP architecture pattern.
- The View layer is extremely light as it only visualizes the data and doesn’t perform any data processing operations.
- Easy to test the code as each interface is separately divided.
- Since each interface handles the conversation to extreme levels, it is crucial to code each interface precisely.
- It takes more time to code the entire interface.
Model View ViewModel (MVVM)MVVM is a further improvement over the MVP architecture pattern. In this pattern, the Presenter is replaced by the ViewModel which handles the entire data processing. However, unlike the MVP pattern, the ViewModel, in this case, doesn’t have any idea about the existence of the View or the Model at all. It operates individually, which results in a smooth flow of data between the three layers. One of the major differences that MVVM has from MVP is the flow of data. In MVVM, the data flows in separated streams and can be collected by the consumer accordingly. Here’s how the MVVM model operates: Model: Like the previous architecture pattern, the Model handles the entire data. Also known as the DataModel, it’s only responsibility is to expose data for the ViewModel after retrieving it from different sources including the database as well as the network layer. Basically, the DataModel layer holds the entire business logic. View: View, in this case, performs the same task like MVP model, i.e., visualization of the data. It is basically the user-interface which is responsible for displaying and collecting the data through user events. It then passes the data to the ViewModel in the form of data streams. Once the ViewModel has the desired response to the user query, it again passes this information back to the view. ViewModel: The ViewModel performs all the logical operations on the data retrieved from the DataModel. It accepts the data streams from the DataModel and binds them together to perform further operations. Once it has processed the data, it passes the data to the View layer in the form of data streams too. In the MVVM architecture pattern, the data consumer, i.e., DataModel is familiar with the existence of the data producer, i.e., ViewModel. The entire ViewModel works individually and doesn’t have any idea about the existence of the DataModel as well as the View.
Pros and Cons of MVVMEven the MVVM model has pros and cons of their own. Here are some of the advantages and disadvantages of the MVVM model.
- Binding operators can be used to write all the XML-attributes.
- Review at the compilation stage.
- Generate individual components to improve the testing process.
- The developers can only operate the View using two methods, i.e., DataBinding and View methods.