In our android team, we follows the generic android and java coding guide as Google Java Style Guide, AOSP Java Code Style for Contributors, Ribot Android-Guidelines and RAIN Android App Java Styles. And in some place, we have some accustomed style our teams and projects, for example, the class’s field naming is a little different from previous recommended ones.
Class Fields Naming
- Static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.
- Static mutable field names start with
s
. - Member field names of the non-model class should start with
m
.
The definition of non-model class is that class has complex algorithm and complicated business logical, e.g. classes of Fragment, Activity, custom view, account manager, network client and etc.
Here we can discuss more but it’s easier to code review on Github if there is
m
ors
for field names. We can easily identify it’s local variable or member variable.
- Member field names of the model class (like C/C++ structure) shouldn’t start with
m
.
The definition of model class is that class looks like C++ structure, sometime it has little and simple business logical, but the major usage of this class is to store information and instances. For example, ViewHodler, data model and etc.
I don’t suggest to add prefix
m
to member field name or not just depending on whether it’s public or non-public field.
- If this field’s type is an android component, it should add component as postfix, for example,
ImageView titleImageView
,Button addToCartButton
. And it's the same guild for custom view, for example,NoResultView noResultView
. - Field names start with a lower case letter.