Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Clean Architecture, usecase dependencies

Recently, I found my way to The Clean Architecture post by Uncle Bob. But when I tried to apply it to a current project, I got stuck when a usecase needed to depend on another usecase.

For example, my Domain Model is Goal and Task. One Goal can have many Tasks. When I update a Task, it needs to update the information of its parent Goal. In other words, UpdateTask usecase will have UpdateGoal usecase as a dependecy. I am not sure if this is acceptable, or, if we should avoid usecase level dependencies.

like image 391
Tuấn Vương Avatar asked Nov 07 '16 05:11

Tuấn Vương


People also ask

What is Usecase in clean architecture?

In Clean Architecture "use case" (or "use case interactor") refers to the class/component which contains the business rules/business logic. The Dependency Rule defines that the use case (the business logic) should not have (compile) dependencies to the view, any external framework or IO.

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)

Is clean architecture onion architecture?

Clean ArchitectureIt builds on the concepts of Onion Architecture but with somewhat different details of the layers. Instead of “Domain Model”, it refers to the core as “Entities”, but still representing enterprise-wide business rules.


1 Answers

A use case is related to a functionality of your application. Generally when we need to invoke from one use case to another there is something that does not work.

When you update a goal in isolation, it is not the same scenario as when you update it by a change in a task, in fact, it is sure that not all data is updated, but a part.

Surely you will have to use the goal repository and the goal entity but it is a completely different scenario. In your case you are not duplicating logic, only calls to the repository or the entity, saving code lines can be expensive in the future.

In short, it is not a good idea to have dependence between use cases.

like image 124
xurxodev Avatar answered Sep 17 '22 16:09

xurxodev