Answer the question
In order to leave comments, you need to log in
How is this clean architecture + mvvm implementation option?
Hello. I would like to ask you for advice. I thought about the implementation of clean architecture + mvvm and came to an option.
1) There is a viewModel, it implements an interface, let's call it ViewModelObserver and there, for example, there will be a method provideList (data: MutableList).
2) The ViewModel constructor has interactors for each action. For example, InteractorGetList has an execute method.
3) From the viewModel, the execute method is called, which passes the result to the provideList() method
4) I checked through leakCanary for no leaks.
ViewModel
Source Code
class FragmentItemsViewModel(
var testInteractor: TestInteractor
): BaseViewModel(), ViewModelObserver{
override fun provideData(data: MutableList<String>) {
var f = 1
f = 2
}
fun doOperation(){
testInteractor.execute(viewModelScope, this)
}
}
class TestInteractor {
fun execute(scope: CoroutineScope, observer: ViewModelObserver)= scope.launch{
var data = withContext(Dispatchers.IO){
delay(5000)
[email protected] generateData()
}
observer.provideData(data)
}
fun generateData(): MutableList<String>{
val data = mutableListOf<String>()
for(i in 0..1000)
data.add(i.toString())
return data
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question