Revision - MVVM Flashcards

(12 cards)

1
Q

What is the most important underlying principle to follow when designing an app with MVVM architecture?

A

Separation of Concerns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List out 4 Short-Term Hacks that might Provide Technical Debt to project

A
  1. Tailoring our app to a specific device
  2. Placing all business logic directly in the UI file
  3. Hardcoding user-facing strings directly in the code
  4. Blindly copy and paste code into files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List out 2 Broad Layer of a Flutter application in MVVM

A
  1. UI Layer (View and ViewModel)
  2. Data Layer (Repository and Services)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which type of logic is acceptable to put inside a View?

A
  1. Logic (If Statement) that is used to hide/show widgets
  2. Animation Logic
  3. Layout based on Screen Size
  4. Simple Routing

It should not contain any Business Logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List out 3 primary responsibilities of a ViewModel

A
  1. Retrieves data from repositories and transforms into UI State
  2. Maintains current state so View can rebuild without losing data
  3. Exposes callback that the view can trigger
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the strictest rule a ViewModel must follow regarding the UI?

A

ViewModel must not reference any UI components

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the role of a Repository in MVVM?

A

Provides a single, clean API to the app by fetching data from network database or cached database data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the role of Service?

A

Sits at the lowest layer and wrap external API endpoints, was used only to isolate data-loading and hold no state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the strict rule of multiple Repositories interact with each other?

A

Repository should never be aware of each other. If data from 2 repositories needs to be combined, it should happen in the ViewModel or Domain layer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

List out the 3 reason why we need a good app architecture

A
  1. Makes it easier for developers to collaborate
  2. Makes the code easier to test
  3. Save time and reduces technical debt as we extend out app
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is LiveData and why is it crucial for MVVM?

A

It is an observable data holder that is lifecycle-aware. It keeps the UI up to date but knows when the device rotates or the app stops, preventing crashes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

List out 3 mandatory components required to build a Floor database

A
  1. Entity (Database schema/Table)
  2. DAO (Data Access Object - Define read/write SQL operations)
  3. Database (Holder class that creates connection)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly