Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of CLEAN architecture in Android with Parceler

I'm using working on a project in the CLEAN architecture where the project is broken into the "Presentation", "Domain" and "Data" modules, where the Domain module hosts the "Entities" that are basically the data models specific to this project. An example of this architecture is here.

Unlike the other two module, "Domain" is a pure Java library module, which is great for clarity and testing as it doesn't have the Android overhead, however it also means I'm now not able to use libraries like "Parceler" to which is very Android specific. Is there a way around this?

like image 710
Billy Avatar asked May 19 '16 03:05

Billy


1 Answers

Parceler allows you to configure beans outside of the given module to generate a wrapping Parcelable via the @ParcelClass annotation. This means you can configure the given bean as a @Parcel outside of the Data layer, and in the presentation layer (or wherever else you want). See http://parceler.org/#classes_without_java_source for specifics.

The org.parceler:parceler-api module is also pure Java, it has no dependencies on the Android api. Therefore you should be free to annotate your Data module without violating the CLEAN archetecture you're seeking. The annotation compiler portion (org.parceler:parceler) of the library, however, does rely on the Android API, so you'll need to run it in the android-specific module. This leaves you with the follow:

  1. Include the parceler-api library in your Data module and annotate your Data layer beans (@Transient, @ParcelProperty, etc). If you don't need any specific configuration, you can avoid including the parceler-api as a dependency.

  2. Add the parceler and parceler-api libraries to your Android-specific module (Presentation?).

  3. Add a @ParcelClass annotation with each class from your data module you want to be an @Parcel to an arbitrary class (Application?). This will direct Parceler to generate a Parcelable for each class identified within the @ParcelClass parameter.

like image 68
John Ericksen Avatar answered Sep 18 '22 20:09

John Ericksen