Organization of source filesOverview
Android apps should always be organized neatly with a clear file structure, which makes your code easier to read.
Here are a few best practices for organizing the package structure of your app.
Organize packages by category
The way to do this is to put the same group of things together in their category, each component in the appropriate package:
com.example.myapp.activities-Inclusive of all activities
com.example.myapp.adapters- contains all the custom adapters
com.example.myapp.models-A model with all our data
com.example.myapp.fragments-Contains all the fragments
com.example.myapp.helpers-Contains all the Help classes (custom code that supports this app).
com.example.myapp.interfaces-Contains all the interfaces
Keeping these folders in each application means that the code is organized logically, and browsing the code will be enjoyable.
Organize packages with application features
Use packages to react to feature sets by feature packages, taking into account the following package structure:
com.example.myapp.service.*-is a child package/class for all background-related services
com.example.myapp.ui.*-is a child package/class that is related to all interfaces
com.example.myapp.ui.mainscreen-Contains some classes related to the application home screen
com.example.myapp.ui.detailsscreen-A class that contains a detailed screen of the project with the app (translator Note: Here I would like to explain, this place is a detailed display of a place, such as the news we often read, Mainscreen only a title, click in the Detailsscreen to show detailed news information)
This feature allows you to detailsactivity , detailsfragment , detailslistadapter , detailsitemmodel put it in the same package when you use " project details feature, which provides a comfortable navigation.
DetailsListAdapterand DetailsItemModel classes and/or their properties can be made into private packets, thus not exposed to the outside of the package. In this package you can directly access their properties without generating a template of tons of "setter" methods.
This allows the creation of objects to be very simple and intuitive, while objects outside the package remain intact.
Conclusion:
It is up to you to decide which of the above methods is best for your project.
However, for a generic Java program, it is considered best and most meaningful to encapsulate the application by feature.
Reference:
- Http://blog.smartlogic.io/2013/07/09/organizing-your-android-development-code-structure
- Http://stackoverflow.com/questions/5525872/android-project-package-structure
- http://www.javapractices.com/topic/TopicAction.do?Id=205
This article is mainly about the package name of the problem, very meaningful, general development, I am more commonly used is the first classification, which resulted in a functional module of related classes in a lot of packages inside, sometimes in order to maintain also spent a good effort to find each class, the following function to divide, is indeed a very good choice.
Explore the organization of Android source files based on application development