Iqbal Ahmed
12/08/2022, 8:05 AMJavier
12/08/2022, 8:33 AMcurioustechizen
12/08/2022, 9:01 AMMy understanding is, usecase should not depend on any other usecaseDo you remember where you came across this advice and what was the reasoning behind it? Almost every architecture I worked with had the opposite advice: The whole purpose of a UseCase is to depend on as many other UseCases or depend on as many repositories as needed to achieve a single goal.
and all these operation should be done in presentation layer in my case ViewModel (Android).Again, this in my opinion is misleading. Your ViewModel should only concern itself with presentation logic. Coordinating between multiple "backends" (I use this term loosely here) to get the data needed to display this screen is not presentation logic. It belongs in UseCases (or further down depending on what the logic is as Javier mentioned above)
Iqbal Ahmed
12/08/2022, 9:25 AMIqbal Ahmed
12/08/2022, 9:26 AMIqbal Ahmed
12/08/2022, 9:28 AMJavier
12/08/2022, 9:33 AMcurioustechizen
12/08/2022, 9:40 AMand Is it a good practice to use one usecase in another usecase ?Good practices are subjective; but in all the apps that I worked on in the past 4 years, we've made extensive use of the pattern where a UseCase depends on other UseCases.
Iqbal Ahmed
12/08/2022, 9:48 AMIqbal Ahmed
12/08/2022, 9:49 AMJavier
12/08/2022, 9:52 AMIqbal Ahmed
12/08/2022, 9:57 AMJavier
12/08/2022, 10:02 AMJavier
12/08/2022, 10:04 AMcurioustechizen
12/08/2022, 10:05 AMbut if we include mulitple usecase in another usecase, then it’s break SRPCould you explain this? I don't agree with this.
so should I create one usecase and include all the usecase insde one, calling composite usecase.This is exactly what I'm referring to. Your smaller UseCases are units of composition. You can compose them into a larger UseCase (like a screen-level UseCase in your example). The smaller UseCases still perform a single action; they can still be unit tested in isolation and they can still encapsulate some bit of logic (that might change in the future; so all UseCases that depended on it get the change for free).
Javier
12/08/2022, 10:05 AMIqbal Ahmed
12/08/2022, 10:09 AM