Clean architecture in Android (Jetpack Compose, Kotlin, MVVM) ーPart- 1
Making an android application is kind of easy( Compared with creating with Clean architecture . Please feel free to debate me 😃) but making an application with clean architecture is another thing. Recently I am learning about clean architecture on Android. Today I will talk (Actually write )about it.
First, we have to know some theories. I know theories are boring. So I will make it as short as possible. Also, I have created a GitHub repository about this. So feel free to check it.
Why do we need clean architecture?
Coding is an art. An application does not mean it works and meets UI/UX requirements. It also needed to be easily understandable, flexible, testable, scalable, and maintainable(Lots of fancy words . I know 😃). For a simple application, it may not be needed but for a robust one, it is mandatory. Clean architecture is a hot topic in mobile application development. Because the complexity in mobile applications is increasing. So as a developer we must have knowledge of this.
Layers of clean Architecture
There are three main layers of clean architecture.
- Domain: Execute business logic that is independent of any layer and is just a pure Kotlin package with no android specific dependency. It includes the Model, Use case, etc.
- Data: Provide the required data for the application to the domain layer by implementing the interface exposed by the domain layer. It includes Remote / Local data sources, API implementation, etc.
- Presentation/ Application: It contains android specific code which executes the UI logic. It includes View, Fragment, activity, dependency injection, etc.
I just describe according to my understanding. If you want to know more please check this blog.
- Domain Layer can not access any Layer, Data layer can access only Domain Layer, and App layer can access both.
- UseCase is used to take requests and pass data to the request mainly in the Presentation/App layers. UseCase is in the Domain layer.
- The domain layer only has Kotlin/Java…