https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
l

luke_c

01/22/2022, 10:59 PM
If you have a use case e.g. SearchUserUseCase and the UI should only go into a loading state when some validation passes, e.g. search term more than 3 characters, then where would you put that validation? It can't go in the UseCase because the ViewModel has to set the loading state before calling it but the validation could fail If it goes in the ViewModel then that validation logic becomes something you need to copy to all other places that use your UseCase. That's probably the best option, but if the validation was more business critical then what would you do? Separate use case for validation?
k

K Merle

01/23/2022, 8:06 AM
I always put UI related logic in ViewModel.
v

Vahalaru

01/24/2022, 3:25 AM
I agree with @K Merle, UI logic goes in ViewModel and to me, logic validation is UI logic.
6 Views