Search code examples
androidmvvmandroid-architecture-components

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.


Solution

  • 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/