Best practice for package structure in an MVP proj

2019-03-10 11:30发布

I have an Android Studio project that is using an MVP architecture. What is the advised packages structure for a project this style we can do:

app:
  screen_name
    activityA
    presenterA
    interfaceA

or:
   activities
     activityA
     activityB
   preentors
     presentorA
     presentorB
etc

3条回答
Bombasti
2楼-- · 2019-03-10 11:45

In addition to the other answers i would recommend to look at android architecture blueprints, which may give you ideas of how to organize and implement your application.

查看更多
成全新的幸福
3楼-- · 2019-03-10 11:52

Your problem is just only ui part of MVP which is View classes along with their corresponding Presenters. And the better solution is the second structure.

enter image description here

App should have package according to features not by the common functionality. So we should group together the classes which are getting changed/modify together.

Mostly developers group them like this because they do this to keep the same package structure for all the applications they work on. But that is very wrong decision cause it is always hard to find classes when they are grouped only because they share same parent classes!

Like all activities most developers put in activity package because all activity classes extends the Activity class. That makes sense that this is only activity related package but it is hard to go through those packages.

For more information, see: android-mvp-architecture and this S.O answer

查看更多
唯我独甜
4楼-- · 2019-03-10 11:52

MVP is good choice. You can follow following pattern:

app: 1. activities: + interface to represent view (i.e activity) + actual activity java class 2. Presenter: + interface to represents presenter + java class to represent presenter implementation 3. Model: + interface to represents model + java class to represent model implementation (do network calls here, pass callback to presenter which then gives data to activity)

查看更多
登录 后发表回答