views:

327

answers:

5

Hi guys,

if I have the following private member:

private int xIndex;

How should I name my getter/setter:

getXindex()
setXindex(int value)

or

getxIndex()
setxIndex(int value)

EDIT: or

getXIndex()
setXIndex(int value);

?

+1  A: 
getXindex()

I always use first letter upper case after "get" keyword.

EDIT : I am convinced :D getXIndex() wins!

Xorty
I almost downvoted your answer until I saw the edit
Shervin
+5  A: 

I would use:

getXIndex()
setXIndex(int value)

Consider also renaming the variable to indexX.

kgiannakakis
+12  A: 

Should be:

getXIndex()
setXIndex(int xIndex)
Samuel Yung
A: 

I think getXindex() is the best way. The getter should start with 'get', followed by the member name, with its first letter capitalized. Also the latest conventions I heard of, say that we should avoid multiple capital letters one after another. For example getHTMLtooltip is wrong. it should be getHtmlTooltip instead. Also you should try to make all your members final and there should not be a need of setters, since the class will be immutable ;)

m_pGladiator
Why all members final???
Simon
@m_pGladiator: re immutable: while this is obviously desirable, not all classes can be made immutable. but of course: setters should only be present if needed. @Simon: the main reason is thread safety. if a class is immutable, no problems of concurrent modification through separate threads can ever arise
seanizer
Sorry, I didn't read the "javabeans" tag. The beans architecture presumes getters and setters and does not favor immutability
m_pGladiator
+1  A: 

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.

ayush