Tips: Android design pattern

Web Hosting
Design Pattern, design pattern is a general reusable solution to a commonly occurring problem, In case of Android, I personally feel that existing design patterns like MVC, Abstract Factory,Singleton,etc. are not fit with the Android. Most of design patterns was evolved before the era of Android/Mobile. I think that code should be simple and optimise, does not matter which design pattern you are using. 

In this article I am going to explain few rules/pattern which I am following in my projects.


1. Package Structure
         src 
             com.client.app                   - contain Application class only
             com.client.app.views           - contain all activities
             com.client.app.fragments    - contain all fragments
             com.client.app.webservice   - contain all web services
             com.client.app.adapters      - contain all adapters
             com.client.app.db              - contain all db related classes
             com.client.app.models        - contain all models
             com.client.app.utils            - contain utility/misc classes
             com.client.app.widgets        - contain extended/custom views
             com.client.app.services       - contain all services
             com.client.app.animation     - contain all animations

2. Naming convention for Xml files

  • activity_<ACTIVITY NAME>.xml - for all activities
  • dialog_<DIALOG NAME>.xml  - for all custom dialogs
  • row_<LIST_NAME>.xml - for custom row for listview
  • fragment_<FRAGMENT_NAME>.xml - for all fragments
3. Naming convention for component/widget in xml files.

  • all component for x activity must be start with activity name
  • all component should have prefix or short name like btn for button
  • For example,name for login activity component should be like following.
    • activity_login_btn_login
    • activity_login_et_username
    • activity_login_et_password
  • Short name of major components
    • Button - btn
    • EditText - et
    • TextView - tv
    • Checkbox - chk
    • RadioButton - rb
    • ToggleButton - tb
    • Spinner - spn 
    • Menu - mnu
    • ListView - lv
    • GalleryView - gv
    • LinearLayout -ll
    • RelativeLayout - rl
4.  Reference links related to Android design pattern / architecture


Web Hosting

No comments:

Post a Comment