Android的封装结构的最佳实践 [英] Android Package Structure Best Practice

查看:102
本文介绍了Android的封装结构的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于应用程序包结构的最佳实践的问题。

I have a question regarding best practices for application package structure.

我看了雷托•梅耶尔的谷歌I / O 2011 presentation <一href="http://www.google.com/events/io/2011/sessions/android-protips-advanced-topics-for-expert-android-app-developers.html">"Android Protips:高级主题专家Android开发的,看他的博客文章深入了解位置和他指出,应用程序包的结构:

I watched Reto Meier's Google I/O 2011 presentation "Android Protips: Advanced Topics for Expert Android Developers" and read his blog post "A Deep Dive Into Location" and noted his application package structure of:

融为一体。 ... .content_providers
   COM。 ... .receivers
   COM。 ... .services
   COM。 ... .UI    COM。 ... .UI.fragments
   COM。 ... .utils
   COM。 ... .utils.base

com. ... .content_providers
com. ... .receivers
com. ... .services
com. ... .UI com. ... .UI.fragments
com. ... .utils
com. ... .utils.base

这是在preferred结构包?有没有更好的结构?

Is this the preferred structure for packages? Is there a better structure?

推荐答案

打包课程的主要目标是通过源$ C ​​$ C,以简化导航。这对于开源软件尤其重要。在我看来,一个易于浏览的封装结构包括以下包:

The main goal of packaging your classes is to simplify the navigation through your source code. This is especially important for open source applications. In my opinion, a easy-to-navigate package structure includes the following packages:

com.example.main - 包含您的主要驱动力的功能,如您的主要活动(S),你的应用程序类(如果有的话),等等

com.example.main - contains your main driver functions, such as your main activity(s), your application class (if you have one), etc

com.example.conf - 包含您的配置文件,如含常量(static final的变量)

com.example.conf - contains your configuration files, such as those containing constants (static final variables)

com.example.net - 与网络相关的课程,如那些发出HTTP请求

com.example.net - network-related classes, such as those that make http requests

com.example.util - 实用工具类,如服务,BroadcastReceivers或其他后台进程

com.example.util - utility classes, such as services, BroadcastReceivers, or other background processes

这篇关于Android的封装结构的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆