howa <> wrote:
> I have a class, which has a variable store the state of the class,
> e.g. isRunning
> However, when I want to add a public method to access to this
> variable, I wonder should I use getIsRunning or simply IsRunning?
> seems getter (getXXX) is a normal way, but the method name seem to be
> dummy....
First, for all style conventions' sake, you definitely should
NOT call it "IsRunning" (with capital first letter).
Mixed-case-starting-w/-capital is reserved for Class-names.
Second, I wouldn't call the field "isRunning", but perhaps
just "running". I'm not sure if this is covered by Style-
guides, though.
For "isRunning()" versus "getRunning()" (or "getIsRunning()"),
I'd decide to use get...(), if the method really just returns
the attribute, and is...() if the information returned is more
or less calculated, like in "return state==State::RUNNING".
But this rule is not very strong, so isRunning() is still ok,
even if you just return the field's value.
|