Okay, so I am going through the Android development tutorial book: The Big Nerd ranch and I am on chapter two where it tells you that you need to have certain prefixes and not have certain prefixes before getters and setters.
"What is the point of setting these prefixes? Now when you ask Eclipse to generate a getter for mQuestion, it will create getQuestion() rather than getMQuestion() and isTrueQuestion() rather than isMTrueQuestion()."
Why would having getMQuestion()
make a difference, wouldn't it be the same as getQuestion()
?
Thanks
You put "m" prefix before instance property and "s" prefix before class property and no prefix for local variables. It's a standard so it's easier to distinguish variables scopes when reading class implementation details.
When You are reading code of an object method where you see three variables: mValue, sValue, value You know that: - mValue is object property so by modifying it You change object state. - sValue is class property so if You would change it it will affect all objects of that class - value is local property which will be garbage collected as soon as method returns.
this naming convention is class implementation detail which should not be visible from outside as public interface (getters, setters)