Architecture: Separation of concerns - devrath/RunTracer GitHub Wiki
Background
One aspect of software architecture is making it as easy as possible to change the code. Usually when building an application, requirements change from time to time.
Challenges faced
When we make changes as per this requirement, it might lead to changes in many other parts of the codebase which is not good.
Approaching the challenge
- As a result we split the application into multiple parts called layers where each serves a specific purpose.
- So in Android, It is done by
presentation,domain, anddatalayers. - Presentation Layer
- Consists of somehow all the codes that involve presenting the UI to the user.
- Things that involve
Activity,Fragment,View,Composable. - It also includes
View-Modelthat transforms the data that is hard to display into a meaningful way for the user.
- Domain Layer
- This is some logic specific to the domain of your app.
- It is like for example, You can say What should happen in the core of app, instead of how it happened.
- Say a password validation logic in an
e-commerceapp can be an example of this. - The logic of password validation is different for the
e-commerceapp and thebankingapp since it is specific to the domain.
- Data Layer
- Now the data layer represents the communication to the outside world.
- Outside world means, Anything that leaves the scope of your application.
- Meaning says a remote API running on some other server.
- A local database for your app users.
- Any service your app uses from your app.
- This is what we call implementation detail, Meaning how the details are implemented.
- So basically
domain layersays perform login. while thedata layersays how login is done meaning implementation detail.
Dependencies in the layered approach
- Both the dependencies
presentationanddatalayers are allowed to be dependent on thedomainlayer. - They are allowed to access classes defined in the
domain layer. Domainlayer is actually considered as the core of the app.Domainneeds to be completely isolated from the rest of the application.Domaindoes not know what libraries we use and say we are using it for android also. It just contains the core logic of the app.