Is there any best practice for packing MVP layers?

I made some Android apps using MVP methodology,

But I'm not sure if it is better to place objects of different objects of the same function in one package? or pack all layers of elements of different functions in one package with the name of the layer on it?

(What I mean something like this)

Package screenshot

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

Change These are my projects. :)

Big screenshot packages

+6
source share
4 answers

Just to throw my thoughts into the mix. I worked on projects with each of these approaches. Now I prefer the package over features. There are two main reasons why I prefer this approach:

Ease of induction

Increased visibility of the project structure for developers new to the code base. When classes related to one function are grouped together, it is much easier for a new team member to find out how everything fits together.

Class access restriction

This is probably more important. When you pack by type (all speakers together, etc.), you must provide many methods in these public access classes. This can lead to improper use of these functions from various areas of the code base.

If you are package by function, then these classes are in one package, and thus you can provide access to the package level of methods. This ensures that the methods do not leak.

+5
source

You must create a separate package for the base classes and MVP packages for each MVP object. Let's say "mvp_base" for the base material and the "some_screen" package, inside which you will have your activity, fragments, etc. The specific mvp implementation for "some screen" is placed in the "mvp" package inside the "some_screen" package. It is also recommended to store all your models and presentation inside the Service and be attached to it when creating the user interface.

+1
source

Create a custom package containing the Contract interface containing the View and Presenter interfaces. The package of functions also contains implementations of the View and Presenter interfaces (i.e., the Activity and Presenter classes).

I made a sample project here; You can refer to it for more information on MVP.

+1
source

I prefer this packaging model in the main package:

enter image description here

  • General classes are executed mostly.

  • Each package is a function of the application or application level.

  • Data: data level. Contains classes that are used for data. For example, domain classes, repository classes, data source classes, etc.

  • If you create Mvp - pure architecture and do your work in Interactor classes. (or Use-Case ) you can create a domain package in a related function and put them in this place.

  • Util contains usage classes.

  • View and presenters are defined in a class named Contract .

Here is an example of the Contract class:

 interface SupportContract { interface View extends BaseView { void showTenthChar(char c); void showEveryTenthChar(@NonNull char[] chars); void showEveryWordWithCount(@NonNull HashMap<String, Integer> data); } interface Presenter extends BasePresenter<View> { void onSupportDataRequested(); } } 

In my opinion, the main advantage of this model is that when the package model can easily understand the layers, functions and requirements of the application.

+1
source

All Articles