Android Architecture Patterns



Introduction

When you are working on building a complex android application. It is recommended that you should follow one of the android architecture patterns so that in future it will become easy to manage and update your project. Android architecture patterns are generally used to provide proper structure for the code. There are three different types of architecture patterns which are followed in android are as follows ?

  • MVC (Model View Controller)

  • MVP (Model View Presenter)

  • MVVM (Model View ViewModal)

The main usage of Android architecture patterns is to separate UI from the business logic and make it easy to maintain.

Advantages of using Android Architecture Patterns

  • Applications developed using Android architecture patterns are easy to understand and easy to manage. Along with that changes required within the application can be easily made without disturbing the complete flow of the project.

  • Using android architecture patterns helps us to add test cases for your code and provides the ability to test the code.

Disadvantages of using Android Architecture Patterns

  • Understanding the architecture patterns and writing code according to that is time taking and a complex process.

MVC (Modal View Controller)

Modal View Controller is an architecture pattern which tells to separate code for android application in 3 layers which are as follows ?

  • Model ? Model layer in MVC is responsible for handling data which is being used within our application. Model class is responsible for communicating and gathering data from a network or database.

  • View ? View layer the name itself tells us to display a view to the user. It manages the UI of the android application which is visible to the end user.

  • Controller ? Controller in MVC contains the core logic of the android application which is used to read and write the data from our Model layer and set this data in our UI layer to display it to the user.

Advantages of using MVC Pattern

  • Unit testing of Modal and Controller class is possible using the MVC pattern.

  • MVC patterns provide functionality to separate modal classes which makes it easier to implement new features.

Disadvantages of using MVC Pattern

  • The code layers are dependent on each other. For example, the UI layer is dependent on the Modal layer to get the data and display it in the UI layer.

MVP (Model View Presenter)

Model View Presenter is an architecture pattern which separated code for android application in 3 layers which are as follows ?

  • Model ? Model layer is used to store the data which is being used within our application. The data can be gathered either from the network or database of the application.

  • View ? View is a UI interface layer which provides visualization of data to keep track of actions to notify users action to present it to the presenter.

  • Presenter ? Presenter in MVP is used to fetch the data from Model and display it in the UI according to the user interaction with the application.

Advantages of using MVP Pattern

  • In MVP the model, view and presenter layer are separated which makes it easy to test the code.

  • MVP doesn't have any relationship with android components.

MVVM (Model View ViewModal)

Model View ViewModal is an architecture pattern which separates the code for android application in 3 layers which are as follows ?

  • Model ? Model is responsible for storing the data which is being used within an android application. This layer is used for the abstraction of data sources.

  • View ? View layer in MVVM is used to get the actions performed by the user within an android application. This layer will inform ViewModal about the user interaction with the View.

  • ViewModel ? ViewModel is used to get the data from the Model and display it to the user through the View Layer.

Advantages of Using MVVM Pattern

  • MVVM makes it easy to maintain the code.

  • As MVVM separates the different layers of the code which makes it easy to test the code.

Disadvantages of using MVVM Pattern

  • Debugging of the application becomes difficult due to complex data bindings.

Conclusion

In this article we have taken a look at What is architecture patterns in android and what are its different types and the advantages and disadvantages of using each architecture pattern in Android.

Updated on: 2023-02-20T14:27:52+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements