Android Simple UseCase - No Rx/Coroutine

Alfred
2 min readAug 26, 2020

A UseCase is responsible for implementing the data flow logic. They request data to repositories and convert them into something usable for the View.

In this blog, we are not going to cover all the various reasons of why to use a UseCase, instead we directly get into sample code.

BaseUseCase

A base UseCase class to define a format for your UseCase. Make sure you only have one public method execute() to invoke the useCase.

Sample: LoginUseCase

This UseCase is responsible to take in credentials and invoke a result callback.

  • The Params class is present inside the UseCase to avoid confusion with other useCases.
  • The Result, a sealed class, presents a single Result so we it can be exhaustively handled.

--

--