https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
m

Moataz Mohamed

02/15/2023, 10:10 AM
Can I add a useCase interface module into the UI module so that this interface be the link between the Domain "UseCases" layer and the UI?. I don't want my Viewmodel module to know any thing about the domain layer. It will be something like when we add the repository interface into domain module layer and the impl into the data module layer. And the data inharce from domain layer.
👀 1
j

Javier

02/15/2023, 10:55 AM
Why you don’t want presentation layer to know domain layer?
m

Moataz Mohamed

02/15/2023, 12:04 PM
I just read about clean architecture implementation. And In the article the author says that it should be an interface that link between usecasess and ViewModel (domain layer" and the UI module). So, data should inharce from interface that in domain and the domain should inharce from ui. The data flow is as like "Data -> Repo in domain -> Interface in UI". I don't know that is wrong or not, that's why I asked :)
j

Javier

02/15/2023, 12:19 PM
in clean architecture presentation layer knows domain layer
image.png
a

Alex Prince

02/15/2023, 2:28 PM
yea, I think you're flipping your dependency directions. Javier is right, everything can know about the domain, it's the core of the onion architecture, the Domain, knows about nothing but itself, so, if you put the interface outside the domain, by definition, you can't implement that in the domain.
To expand on that a bit though, what higher layers shouldn't know about is logic and implementation details of the domain, they know that there's an interface, say
IDoTheThing
, that they can call to do the thing, and it will kick them back the result of trying to do it, but, they have no idea HOW it's done that control flow can flip, but the dependency itself doesn't. For example if the domain needs to get data from the network to do what it needs to do, (say poll an endpoint for a response) it doesn't, and can't, know how to do that, but what it can do, is say I need a dependency of
IPollForResponseTheDomainNeeds
passed into me, which is then implemented in layers farther out and passed in.
18 Views