+ 1

Misunderstanding getters and setters

"Getters start with get, followed by the variable name, with the first letter of the variable name capitalized" Why do we write the first letter of the variable name capital when we can write anything we want ? also when we have two variables x and X one of the getters must have the first letter of the variable name small.

13th Feb 2018, 11:39 AM
مروان سالم بامطرف
مروان سالم بامطرف - avatar
2 Respuestas
+ 2
"Getters start with get, followed by the variable name, with the first letter of the variable name capitalized" This is just a recommended code style. It is not reasonable to have two variables x and X, because it makes a code difficult to understand. You may create getters and setters with any names, but words "get" and "set" are short and clear. If you need to have both x and X variables, names of getters and setters may be like: set_x(), get_x(), set_X(), get_X(), but in my opinion it is the wrong way.
13th Feb 2018, 12:04 PM
Aleksandr