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

Melih Aksoy

08/08/2019, 12:18 PM
Hey all ! I was wondering how do you structure your project to apply dependency inversion between modules - it seems to end up in low modules depending on high ones for sake of inversion - but I was wondering if this is correct approach in general, or something else ?
e

Eric Martori

08/08/2019, 3:08 PM
Following clean architecture principles the inner most module (domain) doesn't depend in any other modules. External modules (network, database, etc) may depend only in modules closer to the center than them. For example:
network
may depend on
domain
but no on
database
i

Ianmedeiros

08/08/2019, 5:28 PM
But following the same architecture, your project structure should expose what it do, not what architecture it uses. So, packaging by feature instead of layer makes sense too.
The downside of modularizing by feature is not enforcing layer visibility
t

tjohnn

08/08/2019, 9:00 PM
I guess it is easy to use this way, the inner module creates interfaces, the outer module implements the interface, and the implementation is injected into inner module as the interface type so it still does not depend on any outer module.
m

Melih Aksoy

08/09/2019, 8:53 AM
CA is what I have right now, but considering DI description these solutions don’t seem complete. Following example above, to apply inversion
domain
should depend on
network
and
database
so it knows what abstractions they need, therefore
network
and
database
don’t depend on anything concrete from
domain
.
t

tjohnn

08/09/2019, 11:00 AM
No, domain is not depending on outer module, I think this is the main idea behind dependency inversion. A purpose of CA is to abstract app specific implementation from anything library/framework and I think it is achieved this way.
m

Melih Aksoy

08/09/2019, 11:36 AM
Inversion says higher level modules should not depend on lower level modules and vice-versa. They should both depend on abstractions.
depend
doesn’t mean gradle dependency here - unlike my question, but it goes that way if I’m to separate
network
from
domain
.
What I’m asking is not how to apply but rather is there another way to do it without making modules depending on each other - in gradle way. Like
domain
depends on
network
to know what abstractions it works with - not to fulfill it’s own rules. I was wondering maybe are some other practices like - just as a thought - creating a middle layer for it.
t

tjohnn

08/09/2019, 11:50 AM
Maybe the
ports
-like layer in hexagonal architecture?
m

Melih Aksoy

08/09/2019, 12:04 PM
Sounds interesting ! I’ll check it out 💃
e

Eric Martori

08/09/2019, 12:51 PM
But
domain
shouldn't depend on
network
.
Domain
defines
interfaces
and it is the
network
job to comply with said interfaces. Doesn't matter what abstractions
network
uses. For example, in domain we define an interface
Copy code
interface NetworkRepositoy {
    suspend fun getUser() : User //user is the domain entity, no depency with network here
}
Then in the network module this interface is implemented. This implementation may depend on external libraries like ktor or retrofit, and will probably map network models to the domain models. But there is no gradle dependency of
domain
to
network
, only from
network
to
domain
I don't know if I am missing something or don't understand the problem properly
j

jalexdev

08/31/2019, 1:15 AM
+1 to what @Eric Martori says.
2 Views