Understanding the Concept of Architecture Patterns (MVC, MVP, and MVVM)

October 08, 2021 Publish By : EXPERT APP DEVS 4 min read Viewed By : 919
application architecture patterns

App architecture design is a part of ensuring that your apps have Simplicity, Testability, Low-cost maintenance. There are so many different architectural solutions there, all of them with advantages and disadvantages. Some key concepts are common between all architecture. The most common and widely used architecture is following:

  1. MVC (Model — View — Controller)
  2. MVP (Model — View — Presenter)
  3. MVVM (Model — View — ViewModel)

The main idea of all these patterns is to organize the project in a proper way and make a project structure good so that all the codes get covered in the Unit Testing. However, it is very helpful in the maintenance of your app, to add and remove features or modules programmers can keep a track of various logic parts.

1) The Model—View—Controller(MVC) Pattern

MVC stands for Model-View-Controller. It is an architecture or an app design pattern that makes a huge application easy. It does not belong to any programming language, but it is a concept that you can use in creating any kind of application.

Model View Controller Pattern

MVC pattern is the oldest android app architecture pattern which simply divides into 3 different layers:

Model - The Model represents a set of classes that describe the business logic and contains a set of data. Responsible for data processing.

View - UI design. It is only helpful for displaying the data that is received from the controller as a result. 

Controller - Events, User Input. The controller is highly responsible for handling the incoming requests. Controller gets the data through the model class to view. A controller performs as a bridge between the Model and the View.

Advantages of MVC Pattern -

  1. Modifications don't affect the model.
  2. Easy to create test cases of the Model and Controller is possible because they do not extend or use any Android class.
  3. Easy to maintain with multiple developers.

Disadvantages of MVC Pattern -

  1. Must have strict rules on methods.
  2. It is challenging to manage controllers for more extensive code.
  3. It’s hard to understand the MVC architecture pattern.

2) The MVP (Model—View—Presenter) Pattern

MVP stands for Model-View-Presenter. MVP is similar to MVC and It's derived from MVC, where the Controller is replaced by the Presenter. A presenter is responsible for handling all UI events and user input. it overcomes the challenges of the MVC. it provides a maintainable codebase.

Model View Presenter Pattern

MVC pattern is the old android app architecture pattern which simply divides into 3 different layers:

Model - The Model represents a set of classes that describes the business logic and data.Model provides communication between the database and network module.

View - Design(User Interface). Directly interact with users like XML, Activity, Fragment. It does not contain any logical implementation.

Presenter - Fetch the data from the model class and return it to view. It also monitors when you interact with the views and processes the input.

Advantages of MVP Pattern - 

  1. Easy to create test cases for each interface.
  2. Reusable Views and presenters
  3. Clear separation of responsibilities between components

Disadvantages of MVP Pattern -

  1. It takes more time to create an entire interface
  2. The code size is excessive making it a complex

3) The MVVM (Model — View — ViewModel) Pattern

MVVM stands for Model-View-ViewModel. It's an organized architecture pattern that overcomes all drawbacks of the MVC and MVP. MVVM separates your UI and business logic. Your code is much easier to understand and the package structure is easy to navigate. Easily we can maintain our project.

Model View ViewModel Pattern

MVVM is an improvised version of the MVP architecture pattern. in this pattern, the Presenter is replaced by the Viewmodel. MVVM allows us to separate the UI logic from the business logic. MVVM architecture pattern mainly divides into 3 different layers:

Model - Model represents the data and business logic of your app. Model and Viewmodel work together to collect and save the data. it’s not directly connected with the view.

ViewModel - ViewModel interacts with the model class and also prepares observable(s) it can be observed by a View. it’s a link between model and view. So, the ViewModel should not be aware of the view who is interacting with.

View - it represents the UI of your application. It observes the Observable(s) exposed by Viewmodel.

Advantages of MVVM Pattern -

  1. Code reusability
  2. Ease of testing
  3. Easy to maintain 
  4. Developer can add any module easily and quick

Disadvantages of MVVM Pattern -

  1. The developers can only manage the View using two methods.  DataBinding and View methods.

Need a consultation?

Drop us a line! We are here to answer your questions 24/7.