Android-cleanarchitecture: Question: prepare data for presentation layer

Created on 4 Jun 2016  路  5Comments  路  Source: android10/Android-CleanArchitecture

Hi,

i am trying to adopt ideas from clean architecture to my app and have following question:
In my view i have to show a summary of data calculated from different entities. I dont know where to do the calculation stuff.

  1. calculate in data layer, so domain will only pass through to presenatation layer, so whats the benefit of domain layer?
  2. get data/entities from data layer and calculate in domain layer and pass then to presentation layer, how to take benfit here from sql and retrieving a summary in a performant way?
  3. get data/entities from data and domain and pass to presentation layer and do the calculation there, every new presentation/view have to do this job.

Is there other options, is there a best practice for such a usecase?
Thanks for any advice.

discussion question

All 5 comments

Hi @misrakli ,
Please answer following questions ?

  1. Is the main feature of your app is calculation ? (calculator app) -- This is Domain/Use case layer
  2. Does calculation stuff is required only for retrieving data (low level calculations) -- This is Data layer
  3. Calculations are required to change layout of application (for example if there are more than n items are available, you need to change UI to store all items) -- This is Presentation layer

I hope you will get my idea, if you have more questions please feel free to ask.

hi @CROSP
thanks for your input.

The main feature of the app is not the calculation itself. The summary (calculation) is only a "view" to the current status of some data processing like a statistics. Imagine a list of tasks with subtasks, each task/subtask can have its own status where different status are supported, the summary is giving the user the current state of the task processing. The presentation layer can decide how to work with this summary like you mentioned, for example show different statistics.

I didn't unterstand what you mean in 2) with "only retrieving data". And how should get the presentation layer in this case the calculated data from data layer, what is the role of the domain layer in this case, as i understood the presentation layer should go to the data layer only with a usecase from the domain layer.

I am going the way, that my data layer gives the required entities for the calculation to the domain layer, the domain layer calculates the summary and provides it to the presentation layer, the presentation layer itself can decide how to deal with those information.

@misrakli In my second option, I mean that if calculations are required for example for setting some arguments for query (amount of data to get from db, some calculations related to db) or http arguments (get params), so everything that is only required to retrieve data.

In your case it makes sense to put calculation logic into Domain layer because this is core of your app ( the main idea of your app).

To sum up

  1. Data layer is just silly and stupid data that comes most of time in raw format, of course if there are some complex queries like "Get the list of all users with facebook account information" you can implement this query using SQL for example on this layer.
  2. Domain Layer is core of app, all processing stuff, calculations, business logic rules, complex filters (like if user have not done any purchase he cannot access some data, in case of filters like valid date, email ... all these can be filtered in UI layer)
  3. UI layer should be responsible only for displaying data, refreshing, handling user events ... I know that Android SDK is built in a way that you have God objects like Activity ,because of Context, but I still try to get rid of any logic inside UI.

This is how I understand Clean Architecture approach, maybe I am also wrong, so I would be grateful for any other responses.

@CROSP
the way you described is already the way i am going.
For the most use cases i have a clear idea of how to solve it with clean architecture
but it is not always easy to find the appropriate layer for the given functionality, i think it also depends on the requirements (functional and non functional). But thanks to the community one can find different views to the problem :-)

@misrakli You are absolutely right. It can be hard to find proper layer to put logic in. I have been struggling with the same problem. In some cases new layers can be introduce, but do not create new layer every time you are not sure where to put some logic.

And again these three layers described by author @android10 is just an example of commonly required layers. You can have app without Data layer at all or any other as well.
The main idea is decoupling and separating of concerns.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiaju-yang picture jiaju-yang  路  5Comments

StuStirling picture StuStirling  路  3Comments

fabius-bile picture fabius-bile  路  5Comments

rshah picture rshah  路  6Comments

ashraffouad picture ashraffouad  路  5Comments