Search code examples
javaandroidmvp

Is there any best practice for packaging MVP layers?


I have done some Android applications using MVP methodology,

But I am not so sure if it is better to place different layers objects of the same feature in a same package? or package all layers items of different features in the same package with layer name on it?

(Which I mean something like this)

Packages Screenshot

Currently, I am following the second rule, but is this the best practice?

Edit: This is my project's whole packages! :)

Packages bigger screenshot


Solution

  • Just to throw my thoughts into the mix. I have worked on projects with each of these approaches. My preference now is to package by feature. There are two main reasons I prefer this approach:

    Ease of Induction

    Increased visibility of project structure for developers new to the codebase. When classes which relate to a single feature are grouped together it is much easier for a new team member to quickly see how everything fits together.

    Restricting Class access

    This is probably more important. When you package by type (all Presenters together, etc) you have to give many methods in these classes public access. This can lead to these functions being used inappropriately from various areas of the codebase.

    If you package by feature then these classes are all in the same package and as such you can give the methods package level access. This ensures that methods don't leak.