Organizing your Source File

Android應用應該使用被以一種簡潔的文件結構組織,使你的代碼更容易閱讀。此外,合理的代碼以及類命名規則是非常重要的,以確保你的代碼整潔易于維護


Naming Convention

Java Code

Type Example Description
Variable incomeTaxRate All variables should be camel case
Constant DAYS_IN_WEEK All contants should be all uppercase
Method convertToEuroDollars All methods should be camel case
Parameter depositAmount All parameter names should be camel case

For Android Classes

Name Convention Inherits
Activity CreateTodoItemActivity AppCompatActivity,Activity
List Adapter TodoItemsAdapter BaseAdapter,ArrayAdapter
Database Helper TodoItemsDbHelper SQLiteOpenHelper
Network Client TodoItemsClient N/A
Fragment TodoItemDetailFragment Fragment
Service FetchTodoItemService Service,IntentService

Android Folder Structure

  • com.example.myapp.activities - 包含所有的activities
  • com.example.myapp.adapters - 包含所有基本的adapter
  • com.example.myapp.models - 包含所有的數據模型
  • com.example.myapp.network - 包含所有的網絡代碼
  • com.example.myapp.fragments - 包含所有的fragment
  • com.example.myapp.utils - 包含有的幫助代碼
  • com.example.myapp.interfaces - 包含所有的接口
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容