MVP项目中包结构的最佳实践 [英] Best practice for package structure in an MVP project
问题描述
我有一个使用MVP架构的Android Studio项目. 这种风格的项目的建议包装结构是什么 我们可以做到:
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
推荐答案
您的问题只是 MVP架构模式的 UI 部分.这是 View 类及其相应的 Presenters .更好的解决方案是 first 方法.
Your problem is just only UI part of MVP architectural 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:对于活动,某些开发人员将它们放在activity
包中,因为所有活动都扩展了Activity
类.这是有道理的,因为这是仅活动包,但很难遍历这些包.
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.
有关更多信息,请参见: android-mvp-architecture 以及此SO answer
For more information, see: android-mvp-architecture and this S.O answer
这篇关于MVP项目中包结构的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!