Architecture Patterns in Android for beginners

Richa Sharma
3 min readNov 7, 2021

In this blog we will go through different types of Android Architecture first we should know What is an Android Architecture? and Why we use it?

What is an Android Architecture Patterns?

  • An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context.
  • Android Architecture Patterns use to structure the project’s code and to give it a modular design it basically separate the code into different parts and are applied to separate the concerns.

It is very helpful in the maintenance of the software, to add and remove features and developers can keep a track of various crucial logic parts.

Common Android Architecture are given below :-

  • MVC — Model View Controller
  • MVP — Model View Presenter
  • MVVM — Model View ViewModel

1.) MVC(Model View Controller)

  • MVC pattern is the oldest android app architecture which simply suggests separating the code into 3 different layers :
Work Flow of MVC
  • This is the default approach with layout files, Activities/Fragments acting as the controller and Models used for data and persistence.
  • Its name refers to the three ways to classify the classes in your code:
  1. ) Model : It’s basically our Data class which we use to handle domain logic and to communicate with database and network layer. We can also say Model is our layer of storing data.
  • In Kotlin we use Data classes, while in Java they were called POJOs (Plain Old Java Object)

2. ) View : As name defines it is UI Layer.It provides the visualization of the data stored in the Model.It is mainly XML everything the user sees falls under this category.

3. ) Controller : This layer establishes the relationship between the View and the Model. It gets informed of the user’s behavior and updates the Model as per the need.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

2.) MVP(Model View Presenter)

  • MVP pattern overcomes these challenges of MVC and provides an easy way to structure the project codes.
  1. ) Model — This handles the data part of our application or storing data.
  2. ) View — UI Layer responsible for laying out views with the relevant data as instructed by the Presenter.
  3. ) Presenter — Presenter is responsible for handling all the background tasks.Fetch the data from the model and applies the UI logic to decide what to display.

MVC Vs MVP

  • In MVC controller and View layer falls in the same activity/fragment this approach lead to closely coupled to both UI and the application data processing mechanism but in MVP communication between View-Presenter and Presenter-Model happens via an interface.
  • MVP highly supports Unit testing over MVC.

3. MVVM (Model View ViewModel)

  • Model: This layer is responsible for the abstraction of the data sources. Model and ViewModel work together to get and save the data.
  • View: The purpose of this layer is to inform the ViewModel about the user’s action. This layer observes the ViewModel and does not contain any kind of application logic.
  • ViewModel: It exposes those data streams which are relevant to the View. Moreover, it servers as a link between the Model and the View.

1.) Property Changed Events

2.) UI Events

3.) View Model Data

4.) Read data

5.) Write data

6.) Model Change Events

We will go through each pattern with example in detail in next blog.

Happy Reading :)

--

--