Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better for Android MVVM package by feature or package by layer?

Another "which is better" question, I know these are highly subjective. My definition for better would be:

  1. Being used by the best dev teams
  2. Best for unit testing
  3. Most modular / easiest to build out a prod app
  4. What Google recommends (this is where I'm most confused)

All of the Android blueprints use package-by-feature:

https://github.com/googlesamples/android-architecture

/tasks
/addedittask
/taskdetail

and all of the architecture components samples using package by layer:

https://github.com/googlesamples/android-architecture-components

/db
/model
/ui
/persistence

I'm confused because at the bottom of the Architecture Components site, it actually has links to the Android MVP and MVVM blueprint samples, which seems to me to be contradictory.

like image 727
Lou Morda Avatar asked Feb 03 '19 22:02

Lou Morda


2 Answers

Based on Android Architecture guide, and on Clean Architecture, I would suggest this approach

data/
    model/
    remote/
    local/
    Repository
domain/
    usecases/
        GetUserListUseCase
presentation/
    screen1/
        screen1Activity
        screen1Fragment
        screen1ViewModel
    screen2/
        screen2Activity
        screen2Fragment
        screen2ViewModel
core
    common/
    di/

More here: https://www.toptal.com/android/android-apps-mvvm-with-clean-architecture

like image 170
gts13 Avatar answered Oct 19 '22 18:10

gts13


I think it depends on project size. Also in different companies team use different approaches.

I prefer to use in a small project second type of package managing.

If you want to reuse ModelView component, just keep them in feature packages. And maybe with this type:

/db
    feature1/
    feature2/
/model
    feature1/
    feature2/
/ui
/persistence
    feature1/
    feature2/
like image 26
ardiien Avatar answered Oct 19 '22 17:10

ardiien