Architecture Flashcards
Should you store any app data/state in your app components?
No. Because the process of destroying activities is largely out of the developer’s control and therefore they cannot rely on the app data/state in an activity to be saved after a config change or lifecycle change.
What is separation of concerns and how does it bode with Android architecture?
Separation of concerns is about separating code into individual classes that each address a separate concern. Therefore, UI components like Activities and Fragments should only be used to display and handle the UI & OS callbacks. UI components should be slim with as much business logic delegated to the viewModel as possible.
UI components can be destroyed by the OS or user at anytime so it’s best to separate our important data/state into viewModels.
What does it mean to ‘drive your UI from a model’ ?
Models are components responsible for handling the data for the app. Independent from the View objects, they are unaffected by lifecycle changes. Models should be used to supply the data to be displayed in the app components. By basing your app on model classes, the app is more testable and consistent.
What is a ViewModel?
A ViewModel provides the data for a specific UI component. It contains data-handling business logic to communicate with the model, e.g. a repo dependency that it uses to query a data source. The ViewModel knows nothing about UI components so is not affected by config changes like the activity rotating.
What is live data?
An observable data holder that allows other components to monitor changes to objects within the holder without creating rigid dependency paths between them. LiveData components also respect the lifecycle state and include logic to prevent objects leaking and excessive memory consumption.
What is MVVM?
Model, View, ViewModel is an architecture pattern that allows for the separation of the UI, business logic and back-end data repositories.
- The ViewModel is responsible for exposing the data objects to the view.
- The View is responsible for listening to changes from the ViewModel and displaying the data its given, it is also responsible for receiving user interaction and forwarding the handling to the ViewModel.
What is the difference between MVVM and MVP?
The main difference is that the ViewModel in MVVM does not have a reference to the View where as the Presenter in MVP does have a reference.