Quantcast
Channel: Active questions tagged use-case - Stack Overflow
Viewing all articles
Browse latest Browse all 81

Should we want to pass Usecase interface as param

$
0
0

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

  1. Usecase is tightly coupled to viewmodel
class NoteViewModel(addNoteUseCase:AddNoteUseCase){  // usecase code}
  1. 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


Viewing all articles
Browse latest Browse all 81

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>