Interview frequency: …
Short answer
An architectural pattern in which state flows down toward the UI, and events and user interactions flow up toward the ViewModel.
Explanation
UDF guarantees a single source of truth. The UI does not modify variables directly; it fires an intent/event (such as OnItemClicked). The ViewModel receives this event, executes the required business logic through repositories, and then produces a new immutable state that the UI picks up and redraws itself.
Code example
// 1. State flows down
val uiState: StateFlow<NewsUiState>
// 2. Events flow up
fun onEvent(event: NewsUiEvent) {
when (event) {
is NewsUiEvent.Refresh -> fetchNews()
is NewsUiEvent.Bookmark -> saveArticle(event.articleId)
}
}Common mistakes
- Modifying state from multiple places inside the UI instead of making the ViewModel solely responsible for emitting states.