In clean architecture, the main core is usecase layer which contains business logics. Now in Android we will use case and pass it to viewmodel as param in constructor. For example
class AddNoteUseCase(noteRepository:INoteRepository):IUseCase{ override fun invoke(note:Note){ noteRepository.addNote(note)}}
I saw two type of code to pass usecase for viewmodel
- Usecase is tightly coupled to viewmodel
class NoteViewModel(addNoteUseCase:AddNoteUseCase){ // usecase code}
- Usecase is loosely coupled to viewmodel
class NoteViewModel(addNoteUseCase:IUseCase){ // usecase code}
If we go with first approach then we cant fake and also it would be difficult for future changes.If we go with second approach then we able to fake for unit testing
My question is which approach will be helpful. Because some says one approach because there is no need of faking the usecase as it only contains one method some says without faking how will you test the usecase