regmoraes
regmoraes

Reputation: 5499

Combining Use Cases/Interactors in Clean Architecture

I'm developing an Android app whose architecture is based on Uncle's Bob Clean Architecture, and I've already implemented many of my UseCases/ Interactors without problems until now.

I have the following use case:

Search Room

So, should I create a single interactor ( SearchOrCreateRoomAndJoin ) or create three interactors ( SearchRoom, CreateRoom, and JoinRoom ) and combine them according to my use case description?

Example:

 Room room = searchRoom.execute(roomOptions)

 if(room != null){
 
     joinRoom.execute(room)

 }else{

     Room room = createRoom.execute(roomOptions)
     
     joinRoom.execute(room)
}

Upvotes: 10

Views: 5771

Answers (2)

Ganesh kumar Raja
Ganesh kumar Raja

Reputation: 221

Name the use-case as JoinRoom (only one use-case is enough here)

class JoinRoomUseCase( searchRepository : searchRoomRepository,
 createRoomRepository : CreateRoomRepository,
 joinRoomRepository : JoinRoomRepository){

            fun execute(param:Param){
                      if(searchRepository.findRoom){
                          joinRoomRepository.join()
                      }else{
                          val room = createRoomRepository.create()
                          room.join()
                      }
            }
}

Upvotes: 0

antonicg
antonicg

Reputation: 944

In my opinion, you should develop the three interactors in order to respect the Single Responsability Principle. If you do that, you increase the maintainability and reutilization of the code, because you could use these interactors separately in other scenarios.

Upvotes: 8

Related Questions