Understanding Android Architecture Patterns

Saloni Doshi
GDSC, IIIT Allahabad
4 min readNov 9, 2021

In this article, we will be discussing the different architectural patterns in androids such as MVC, MVP, and MVVM.

But before that let me ask you why our app requires these architectural patterns?
A simple reason behind this is to maintain and organize the project in a proper way so that all the codes get covered in the Unit Testing. Also, it helps to maintain the software and helps the developer to keep track of each activity easily.

The flow of Article

The Model-View-Controller(MVC) Pattern
The Model-View-Presenter(MVP) Pattern
The Model-View-ViewModel (MVVM) Pattern

The Model-View-Controller(MVC) Pattern

The MVC pattern can be divided into three important components namely — Model, View, and Controller. Earlier, MVC was used for desktop GUIs, but now it’s popularly used for designing mobile applications.

Let’s have a look at its three important components

  • Model — It is used for storing data and also handles the logic related to it.
  • View — This component is used to represent the presentation of data that is the User Interface.
  • Controller — This component acts as an interface between Model and View components. It contains the core application logic and updates the Model as per the user’s need.
Components of MVC pattern

Now, let’s see some advantages of MVC -

  • It provides us with the facility to create multiple views.
  • This pattern’s model returns the data without formatting it.
  • If the MVC pattern is used while developing any web application, it makes the development process faster.

But with several advantages, this pattern has some drawbacks too -

  • This pattern is very hard to understand and is more complex than others.
  • Also, the view component requires frequent updates which takes a longer time to complete and thus falls behind the new techniques.

By this, we can see that the drawbacks of this pattern overcome its advantages as thus let’s see another architectural pattern to improve the shortcomings of this pattern !!

The Model-View-Presenter(MVP) Pattern

This architectural pattern helps us to solve some of the shortcomings of the MVC pattern and thus is a good alternative to the above-discussed pattern.

What is better about this pattern?
It provides -

Modularity
Testability
Maintainable codebase

MVP comprises of following three components -

  • Model — Here again the model is used for storing data and also in handling the logic related to it.
  • View — It is all that the user sees, that is the User Interface. It also notifies the Presenter according to the user’s actions and needs.
  • Presenter — The Model and View communicate with each other with the help of the Presenter. It takes the data from the model and handles the UI updates and thus finally decides what to display.
Components of MVP

Advantages of the MVP pattern -

  • The main advantage of this pattern is that it is quite easy to understand and also it’s easy to maintain its codebase which was an issue in the MVC pattern.
  • Next is that it has well-defined boundaries between its components which makes the testing easier.

The disadvantages of MVP again overcome its advantages -

  • There is a tight coupling between the View component and the Presenter component as there is a reference to the Presenter in the View component and vice versa which leads to less generic code.
  • Also, the auto-UI updates are not feasible in this pattern.

Now let’s discuss the final architectural pattern which comes to the rescue to the above-mentioned problems — The MVVM pattern.

The Model-View-ViewModel (MVVM) Pattern

Like the above-discussed patterns, MVVM also helps to organize the codebase and breaks the code into snippets for better and faster understanding.

MVVM is also known as model-view-binder as it is structured to separate the UI and the program’s logic. Thus, this is the most recommended architecture pattern. Components of this pattern are -

  • Model — This is used for encapsulating the data with which we are dealing thus storing the data and logic related to it.
  • View — Notifies the ViewModel about the user’s action. It does not consist of any program’s logic but only the UI.
  • ViewModel — This component is responsible for coordinating between the View and the Model. It provides the data from the Model to the View in such a manner that it understands.
Components of the MVVM pattern

Benefits of the MVVM pattern -

  • It separates the components from each other thus making the testability easier and developer-friendly.
  • It has code divided into several snippets which makes the maintenance of the codebase easier.
  • By separating the components and also breaking the code into small granules, its efficiency is increased.

Still, we have some disadvantages for this pattern also but it is the most efficient pattern and tries to reduce the drawbacks to the above two methods.

In this article, we discussed the different android architectural patterns and how their use can help the developers to handle the codebase efficiently.

I hope you enjoyed this article and would definitely like to explore the implementations of these patterns.
Thank you for reading this article 😃😃

--

--