Junior — Middle
What design patterns were used in implementing the presentation layer at your previous workplace?
sobes.tech AI
Answer from AI
The following design patterns are often used in Android presentation layer:
- MVP (Model-View-Presenter) — separates presentation logic and business logic, where the Presenter manages interactions between the View and the Model.
- MVVM (Model-View-ViewModel) — the ViewModel binds data and logic to the View through Data Binding, simplifying UI updates.
- Observer — used for tracking data changes, for example, via LiveData or RxJava.
Example of using MVVM with LiveData:
class MyViewModel : ViewModel() {
val data: MutableLiveData<String> = MutableLiveData()
fun loadData() {
// load data
data.value = "Sample data"
}
}
// In Activity or Fragment
viewModel.data.observe(this, Observer { value ->
textView.text = value
})
These patterns help make the code more modular, testable, and maintainable.