ich habe ein problem bei der namenswahl bei methoden. dazu habe ich mal etwas gegooglet:
quelle: http://geosoft.no/development/javastyle.html#General
quelle: http://www.cwu.edu/~gellenbe/javastyle/method.html
---
mir ist nun weiterhin nicht ganz klar, wie ich getter methoden für boolean variablen benennen sollen, wenn diese keinen zustand à la "isReady()" oder "isVisible()" beschreiben, sondern etwas, was die Klasse tut.
angenommen ihr habet ein speziellen GUI objekt, das ein fussball-feld darstellt und ihr wollt ein/auschalten können, ob das spielfeld gezeichnet wird.
paintsField()?
isPaintField()?
isPaintingField()?
...
und nennt ihr dann die variable und die setter Methode entsprechend?
oder würdet ihr die methode ganz umbenennen? etwa in setVisibleField() und hasVisibleField() oder sowas wie
setFieldIsVisible() und isFieldVisible()?
stoße auf auf solche bze. ähnliche situationen, wo mir dann nicht ganz klar ist, wie ich die methode am besten nennen sollte.
This is the naming convention for boolean methods and variables used by Sun for the Java core packages.
Using the is prefix solves a common problem of choosing bad boolean names like status or flag. isStatus or isFlag simply doesn't fit, and the programmer is forced to chose more meaningful names.
Setter methods for boolean variables must have set prefix as in:
void setFound(boolean isFound);
There are a few alternatives to the is prefix that fits better in some situations. These are has, can and should prefixes:
boolean hasLicense();
boolean canEvaluate();
boolean shouldAbort = false;
quelle: http://geosoft.no/development/javastyle.html#General
Use the prefixes get and set for getter and setter methods. Getter methods merely return the value of a instance variable; setter methods change the value of a instance variable. For example, use the method names getBalance and setBalance to access or change the instance variable balance.
If the method returns a boolean value, use is or has as the prefix for the method name. For example, use isOverdrawn or hasCreditLeft for methods that return true or false values. Avoid the use of the word not in the boolean method name, use the ! operator instead.
For example, use !isOverdrawn instead of isNotOverdrawn.
quelle: http://www.cwu.edu/~gellenbe/javastyle/method.html
---
mir ist nun weiterhin nicht ganz klar, wie ich getter methoden für boolean variablen benennen sollen, wenn diese keinen zustand à la "isReady()" oder "isVisible()" beschreiben, sondern etwas, was die Klasse tut.
angenommen ihr habet ein speziellen GUI objekt, das ein fussball-feld darstellt und ihr wollt ein/auschalten können, ob das spielfeld gezeichnet wird.
paintsField()?
isPaintField()?
isPaintingField()?
...
und nennt ihr dann die variable und die setter Methode entsprechend?
oder würdet ihr die methode ganz umbenennen? etwa in setVisibleField() und hasVisibleField() oder sowas wie
setFieldIsVisible() und isFieldVisible()?
stoße auf auf solche bze. ähnliche situationen, wo mir dann nicht ganz klar ist, wie ich die methode am besten nennen sollte.