How would you share little bits of logic across vi...
# android-architecture
u
How would you share little bits of logic across view models? Lets say function sized - no state
b
Using delegation and compose your
ViewModel
using this
Example:
Copy code
class SampleViewModel @Inject constructor(private val sampleInteractor: SampleInteractor) :
    ViewModel(), SampleDialogContract.Interactor by sampleInteractor
t
Why not use functions then?
u
where would you keep them?
d
business logic is not the part of ViewModel. ViemModel should use domain services. Then that little bit of domain logic will stay same between all of ViewModels.
👍 2
I dont know who and when popularized that way of ViewModel understanding.
u
Depends. too general to talk like that. Also one liner use cases are stupid
👏 1
t
You can put the functions wherever. In the same file or in a different file