9

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.

jacefarm
  • 6,747
  • 6
  • 36
  • 46

1 Answers1

10

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.

xurxodev
  • 1,639
  • 20
  • 19
  • 2
    I don't fully agree with your statement and here is my use-case (no pun intended ). I have a use-case that generates an AuthSession for a specific User, this use-case is called by admin role Users in the application. I also have a use-case that authenticates a User with email/password and instead of recreating the logic to generate an AuthSession for the user, I call the other use-case. Now, this is my solution, small teams can deviate, judiciously, when implementing clean architecture but I'm sure large teams are more strict to the guiding principles of clean architectre. – Cory Robinson Jun 27 '21 at 02:24
  • 1
    I do fell something similar to what @CoryRobinson just mentioned. Let's say I have a use-case that validates an username in regards of its availability under a certain list/repository of previously registered users. Also, let's say I have another use-case that registers a new user on the same list/repository. For me, replicating the username availability check would result in a duplicated implementation for the same business logic. – thomazmz Mar 08 '22 at 03:05