Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Use Cases/Interactors in Clean Architecture

I'm developing an Android app whose architecture is based on Uncle's Bob Clean Architecture.

I've already implemented a lot of my UseCases/ Interactors whithout problems, until now.

I have the following use case:

Search Room

  • Main Success Scenario

    1. System search for rooms based on given parameters
    2. System join the user in the room
  • Extension

    1. Room Not Found

      a) System creates a new room based on given parameters

      b) System join user in the room

My question is: Should I create a single interactor ( SearchOrCreateRoomAndJoin ), or should I 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)
}

It's import to say that in some points of my app I execute some interactors like SearchRoom

like image 696
regmoraes Avatar asked Apr 22 '16 19:04

regmoraes


People also ask

What is interactor in clean architecture?

Interactor calling multiple workers. When Interactor needs to perform more than one task, having multiple workers to execute each one of the task is the recommendation of clean architecture — confirming SOLID principle.

What is use case Interactor?

In Clean Architecture "use case" and "interactor" means the same: it is the component which contains business logic. The presenter in this architecture does not contain any business logic.

What are use cases in clean architecture?

The purpose of the Use Cases is to request data to repositories and turn into something usable for the View. Because of that, we are mapping the Crypto model from the Repository to a new view model named CryptoViewModel (I am not very creative 😅).

What are the four layers of clean architecture?

Clean architecture vs. The logical layers of this style are as follows: Presentation layer ( accounts for the presentation to the user) Business logic layer (contains the business rules) Data access layer (processes the communication with the database)


1 Answers

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.

like image 78
antonicg Avatar answered Nov 14 '22 22:11

antonicg