jeudi 3 décembre 2020

Pass too much params from UI to UseCase Android Clean Architecture

I am applying Clean Architecture, but actually still have many questions about it.

Suppose, my API @POST fun createJob(@Body request: JobRequest). And the params are provided from UI. So,

  1. In data: I have created a JobRequest like below:
data class JobRequest(
    @Expose @SerializedName("p1") val p1: String?,
...
    @Expose @SerializedName("p7") val p7: String?
)
  1. In domain: I create a CreateJobUseCase like below:

class CreateJobUseCase(private val userRepository: UserRepository) :
    BaseUseCase<CreateJobUseCase.Input, Job>() {

    override suspend fun execute(input: Input): Job {
        return userRepository.createJob(input.p1, ...input.p7)
    }

    data class Input(
       val p1: String,
       ....
       val p7: String,
   ) : BaseInput()
}
  1. In presentation: I will call from ViewModel like:
   createJobUseCase.execute(CreateJobUseCase.Input(p1, p2...p7)) {
     //handle output
   }

My question is:

In domain, should my UserRepository interface like A or B?

A: suspend fun createJob(input: CreateJobUseCase.Input) : Job

or

B: suspend fun createJob(p1: String,... p7: String) : Job

In many projects, I saw them use B, it seems the repository function is cleared. But, I think A still ok, because it's still flow the dependency rule, and CreateJobUseCase.Input already contains what we need for createJob function. Am I wrong ?

Aucun commentaire:

Enregistrer un commentaire