Home > Enterprise >  When create useCase - clean architecture?
When create useCase - clean architecture?

Time:05-02

I have simple fun in repository it get all dogs

fun getDogs()=apiService.getDogs()

My question is should I create use case for this function? in other words if function doesn't have business rules should i create useCase for it?

CodePudding user response:

As per good programming practices, it is better to create a use case. A use-case will benefit in two ways:

  • LA change in contract in the repository method at a later point in time would not affect your ViewModel implementation. eg. the data returned by the repository method changes or you want to use two methods from the repository to collate data and then return in your use-case.
  • If you are doing something like KMM, then having a use-case layer will be more consistent across.

If your use case is very simple and you are pretty sure that the contract from the repository layer would never change (which is ideally a bad thing to assume), then you may go ahead directly using the repository.

  • Related