Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android clean architecture's Layered structure

I'm building an android app with clean architecture using MVP pattern, and repository pattern at the data layer. I'm a little confused about the business objects. Should there be an object to use in the presentation and another type of same object in the domain/data layers? If so, then where and when to convert an object to the other type?

like image 937
stav elmashally Avatar asked Jun 25 '17 12:06

stav elmashally


1 Answers

While it is technically possible, there is usually no need to have a special representation of domain entities for presentation layer.

Sometimes you might find yourself in position when presentation layer requires several entities to be bundled together (e.g. show information about two users participating in a chat). In such cases, you can define a wrapper that will bundle the required entities together.

However, in my experience, such bundling is rarely required and comes with a price: presentation layer "waits" for all the bundled data even if parts of this data could have already been shown to the user (e.g. information about one user can be shown immediately, but information about the other user is fetched from the server). This reduces the perceived responsiveness of the application.

In general, for a client application, the scheme of domain objects is usually derived from user interface specifications. Therefore, if you find yourself considering a separate representation of domain objects for presentation layer, it is very probable that one of the following design issues already present in the app:

  1. Domain objects used in the application are the same as the ones used for data exchange with the server
  2. Applicaiton's requirements evolved, but the domain objects did not change accordingly

You always want the networking layer to be decoupled from the rest of the application. This includes the schemes that are in use in data exchange with the server. If your domain objects satisfy the constraints imposed by server's API, but do not satisfy the requirements of the presentation layer, then it will be best to introduce "translation" logic between networking layer and the rest of the app.

If application's requirements evolved, but domain objects weren't updated accordingly then, instead of having separate representation for presentation layer, it is best to just review the design and update the entire application according to the current requirements.

like image 135
Vasiliy Avatar answered Sep 30 '22 20:09

Vasiliy