I have a usecase in the domain layer, can it be us...
# android-architecture
h
I have a usecase in the domain layer, can it be used inside data layer , I do not want to have code duplication and I do not want to break he dependence rule
j
you can use usecases whenever you want if it is in an external layer in clean arch
­čą▓ 2
d
I think UseCases are designed to operate as a vertical slice through all the layers. They encapsulate a business process that involves anywhere from the UI layer al the way down to the entity layer.
h
Let us consider a scenario wherein a highly intricate business logic governs the domain of event analytics. I want also to track error is the data interceptor using the same use-case
d
@huthefa Sorry, I do not understand exactly what you are trying to communicate. Are you asking a question?
c
I did this in a side project. The situation was a notification listener implemented in the data layer - which needed access to some logic that is also used by the presentation layer. I put the shared logic in a UseCase and it worked fine.
­čĹÇ 1
Typical examples of UseCases for mobile app architectures show it being called from a UI logic class like a ViewModel or a Presenter, so one might assume that a UseCase should only exist to serve the UI. In many cases this might be true - you run the UseCase in the scope of the Presenter that calls it. However there are many situations where it makes sense to call a UseCase from the data layer too - like I mentioned in my example above.
Another example might be calling a UseCase from your code that runs from WorkManager (periodic sync, stuff like that).
Also, I'm guessing people also use a similar architecture in non-UI apps like a backend server, and I'm guessing they might be employing UseCases even for non-end-user actions. For example, if you have a backend that server the API for your app, it might be employing use-cases to serve a single API request; but it might also be employing UseCases to do periodic work not related to an API request.