Best practice for package structure in an MVP project

懵懂的女人 提交于 2019-12-02 18:53:51

Your problem is just only UI part of MVP architecture pattern. Which is View classes along with their corresponding Presenters. And the better solution is the first approach.

App should have package according to features, NOT by the common functionality. We should group together the classes which are getting changed/modify together.

Some developers group source code by layer - like the second approach - because they want to keep the same package structure for ALL the projects they work on. But that is bad decision because it's always HARD to find classes when they are grouped only because they share same parent classes!

Ex: For activities, some developers put them in activity package because all activities extends Activity class. It makes sense because this is activity-ONLY package, BUT it is hard to go through those packages.

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

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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!