mardi 11 août 2020

Clean Architecture for Android (once and for all)

I've been doing an extensive research on Clean Architecture for Android, but every "author" has a different aproach to it. I think the biggest difference I've noticed is the number of layers they use, some of them use 3 layers (Presentation, Domain, Data), some use 5 layers, kind of, basically they use the previous 3 layers but they divide the presentation layer in "Presentation" and "Framework" also they divide the data layer in "Data" and "UseCases". Something like this: 3 layers 5 layers

Some authors place the Repository (in my case RepositoryMovies) inside the Data layer some others place RepositoryMovies inside the Domain layer, as you can see, is a little bit confusing, that's why today I ask you to try to unify this mess, or at least point begginers in the right direction. Let's say that in this case more abstraction is better, so we're going to use circular one from above.

I'm gonna give you a lot of classes or tools commonly used on Android projects and you should place them under the layer you think they belong to, keep in mind that you can elaborate whenever you feel like it, for example, you could divide RepositoryMovies into RepositoryMoviesInterface and RepositoryMoviesImplementation and place each one on a different layer. So here we go:

  • Movie (POJO)
  • RepositoryMovies
  • Dagger/Hilt (Components, Modules) *again, elaborate if you want to
  • Picasso/Glide
  • ViewModels
  • DatabaseMovies (Room)
  • DaoMovies (Room)
  • GSON/Moshi
  • Fragment
  • Activity
  • LiveData
  • Retrofit
  • UseCases
  • Extension Functions (Kotlin)
  • Coroutines (Kotlin)
  • Adapters (RecyclerView)
  • ViewHolders (RecyclerView)
  • BindingAdapters (Databinding)
  • Services
  • BroadcastReceivers

Those are some of them, you can add what you thinks is going to make developer's life easier.

Aucun commentaire:

Enregistrer un commentaire