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, and data layers. layers drawio
  • 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-Model that 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-commerce app can be an example of this.
    • The logic of password validation is different for the e-commerce app and the banking app 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 layer says perform login. while the data layer says how login is done meaning implementation detail.

Dependencies in the layered approach

  • Both the dependencies presentation and data layers are allowed to be dependent on the domain layer.
  • They are allowed to access classes defined in the domain layer.
  • Domain layer is actually considered as the core of the app.
  • Domain needs to be completely isolated from the rest of the application.
  • Domain does not know what libraries we use and say we are using it for android also. It just contains the core logic of the app.