Aadil Ayub

@aadil

Notes from readings/courses and random nuggets of thought. This is my online scrapbook.

Learning Log: App Architecture (Android Fundamentals)

From Lesson 4 of Developing Android Apps in Kotlin

This lesson talks about the MVVM (Model View, ViewModel) App architecture pattern. The idea is that you should break up your code into different files/classes that are each responsible for a specific job — basically, create a separation of concerns in your app, instead of doing all the logic for everything in random activities and fragments.

Separation of Concerns

Divide your code into classes, each with separate, well-defined responsibilities.

Our App Architecture

We're going to be working with three (3) different classes:

  • UI Controller: Includes activities and fragments. Responsible only for user interface and user input related tasks. You should take any decision making logic out of the UI controller. It is not responsible for the calculations or processing that decides what actual text to draw.

  • ViewModel: The purpose of the ViewModel is to hold the specific data needed to display the fragment or activity it is associated with. ViewModels may also do some simple calculations and transformations on that data so that it is ready to be displayed by the UI Controller.

  • LiveData: The ViewModel will contain instances of a third class, LiveData. LiveData classes are crucial for communicating information from the ViewModel to the UI controller that it should update and re-draw the screen.

diagram


More from Aadil Ayub: