Use Case pattern and MVVM

Hi,
I ask myself about its necessary if I use useCase pattern with a MVVM architecture and repositories. Initially the viewModel comunicate with the repository directly.

So if I want to add a UseCase layer, the viewModel will communicate with the useCase and the useCase with repository.

Why useCase is a class, I could get the same result with protocol?
protocol AddUseCase
protocol FetchUseCase

The only reason I see to create a UseCase class is to add a validation logic (instead of it in the ViewModel) before continuing to repository.

Screen_Shot_2022-05-24_at_16.43.43

1 Like

@jab2109 any suggestions?

Some of the reasons that you may want to use the UseCase class is to 1) have access from multiple repositories 2) to be able to easily reuse the logic in the use case else where. It is not really helpful in simpler apps but comes in helpful on larger complex projects