3

I want to create a project with clean architecture rules. In the presentation layer I will have a view model. Studying the view model, I learned:

"The purpose of a ViewModel class is to contain data for a UI controller such that that data survives configuration changes. Loading, persisting, and managing data are complicated functions that are outside of the scope of what a ViewModel traditionally does."

Thus, I need a domain layer that will contain the business logic. Based on the sources that I studied, the domain layer includes: use cases, domain model and Repository Interface. However, I do not quite understand the purpose of the domain layer. At the moment, in all projects for the example that I found in the use cases, there was only one request execution.

However, I do not understand where such operations should be located as sorting the data received from the server, performing any arithmetic operations on the data, executing any complex logic as a result of interaction with the user interface.

I don't understand which logic can remain in the view model, and which one needs to be transferred to the domain layer. And if the logic is transferred to the domain layer, where it should be executed, in the use cases?

Please help me understand this. I have read many sources, but have not found any project that would help me to discover all the possibilities of the domain layer.

testovtest
  • 141
  • 1
  • 8

1 Answers1

3

One way to understand the difference is the domain layer should never contain any android related logic, i.e, it should be pure java that is only clean business logic that can be taken out of the application and be executed in any other platform, for example in a web application. On the other hand the Viewmodel is aware of all android platform functionalities to assist your Ui needs. Your activities, fragments...etc should rely on the Viewmodel to display whatever they need.

The_Martian
  • 3,684
  • 5
  • 33
  • 61