MVVM ARCHITECTURE

A component architecture is a type of application architecture composed of independent, modular, and reusable building blocks called components. When designing an app following component-based architecture principles, developers save a lot of time from building every inch of an app from scratch.

Why clean code?

Simply, so others can understand it and for the below listed goals.

The goals of these architecture should be;

  • Independent of Frameworks
  • Testable
  • Independent of UI
  • Independent of any Datasource
  • Independent of any external agency

The android clean architecture implementation could make your code clean inside your business application, also your code will be testable more easily than before. You can implement any of android design patterns on your presentation layer without making any changes on your current business logic/requirements, every time you change your design patterns.

Your team can easily manage their own design patterns on each presentation layer based on their needs and problems that they faced, without having many changes in a business logic inside your application modules.

You can always achieve any android design patterns, inside your clean architecture implementation. You can use following implementation of android design patterns;

  • Model-View-Presenter (MVP)
  • Model-View-ViewModel (MVVM)
  • Model-View-Intent (MVI)
  • Model-View-ReactiveProgramming (MVRX)

But, we will discuss the widely used architecture component, and the one which is highly recommended by Google and Android developers team to use, that is MVVM architecture.

Why MVVM?

While using any architecture pattern can be a benefit in your project, with MVVM it’s very simple to separate the business logic of your app from the presentation.

MVVM stands for Model-View-ViewModel architecture. There are several advantages of using MVVM in your projects, such as:

  • Makes the project loosely coupled.
  • Easier to maintain.
  • Simple to add a new feature or remove existing.
  • Very testable code.

It gives great structure to your project and makes it easier to navigate and understand our code.

Google provides its framework with several different components that you can use and build upon to make your job simpler.

This is how Google’s implementation of MVVM architecture looks like:

Model:

This layer is responsible for the abstraction of the data sources. Model and ViewModel work together to get and save the data.

It fetches data either from SQLite database or from the web services.So it is further divided into various components.

  • Repository: It is a component which is responsible for handling the data information that includes where to get the data from either a web service or the local data set.

View:

This part of our architecture helps us build our user interface and the only part our users can interact with directly.

The purpose of this layer is to inform the ViewModel about the user’s action.

ViewModel:

  • ViewModel object acts as an intermediate between View and the Model, meaning it provides data for the UI components like fragments or activities.
  • It also includes an observable data holder called LiveData that allows ViewModel to inform or update the View whenever the data gets updated.
  • It is very crucial, mainly to keep our app from reloading on orientation changes. Which ultimately provides a great user experience.

Ways to Implement MVVM in the Project

There are 2 ways to implement MVVM design pattern in Android projects:

  1. Using the DataBinding library released by Google
  2. Using any tool like RxJava for DataBinding.

Conclusion:

One can easily make android apps without following this architecture, but if we want to make apps that are robust, testable, maintainable and easy to read, then we must use this to our advantage.

I will be writing more on step by step implementation of MVVM architecture, how to follow the best practices and posting materials related to android development.

If you have any questions or suggestions, please leave a comment below.

Connect with me on linkedIn , Github , Instagram & Twitter.

--

--

--

CSE UNDERGRADS 🎓 INVESTOR 📉 ANDROID DEVELOPER 🧑‍💻 ML , DATA SCIENCE 🧮

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

InsTube APK For Android Download

InsTube APK For Android Download

Notifications on Android — The basics

Circled drawable with letters

7.5 Adding Classes for Our Shader Programs

images/Textures/ShaderHierarchy.png

Animation in flutter

How to use Cocos2d-x with Huawei Mobile Services — HMS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rehan Ahmed Khan

Rehan Ahmed Khan

CSE UNDERGRADS 🎓 INVESTOR 📉 ANDROID DEVELOPER 🧑‍💻 ML , DATA SCIENCE 🧮

More from Medium

Android Architecture or Android Software Stack

Android Debugging

Kotlin vs Java: Which is Better for Android App Development?

Best Android App Development Tools & Software