Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

IsRunning() or GetIsRunning()?

Thread view: 
howa - 21 Feb 2007 15:43 GMT
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....
Lew - 21 Feb 2007 15:50 GMT
> I have a class, which has a variable store the state of the class,
> e.g. isRunning
[quoted text clipped - 4 lines]
> seems getter (getXXX) is a normal way, but the method name seem to be
> dummy....

This is a matter of taste, but it is popular for an instance boolean variable,
say

  private boolean running;

not to have any prefix (same as other instance variables), for the setter to
be named set...() and the getter is...(), where the ... matches the variable
name in the usual way:

  public void setRunning( boolean running );
  public boolean isRunning();

The idiom "getRunning()" is also used, but less commonly.

I do not know if the JavaBean specification has rules for this.

- Lew
Knute Johnson - 21 Feb 2007 16:17 GMT
>> I have a class, which has a variable store the state of the class,
>> e.g. isRunning
[quoted text clipped - 22 lines]
>
> - Lew

Most methods that determine state are isSomething.  I usually use a
variable called runFlag and isRunning().  But as Lew said, season to taste.

Signature

Knute Johnson
email s/nospam/knute/

howa - 21 Feb 2007 16:17 GMT
> I do not know if the JavaBean specification has rules for this.
>
> - Lew

Yes, this perhaps is the main concern...
Thomas Fritsch - 21 Feb 2007 16:50 GMT
> This is a matter of taste, but it is popular for an instance boolean
> variable, say
[quoted text clipped - 11 lines]
>
> I do not know if the JavaBean specification has rules for this.
Actually the JavaBean spec has such a rule. It is in the API doc of
constructor PropertyDescriptor(String,Class))
<http://java.sun.com/j2se/1.4.2/docs/api/java/beans/PropertyDescriptor.html#Prope
rtyDescriptor(java.lang.String,%20java.lang.Class
)>

Signature

Thomas

Oliver Wong - 21 Feb 2007 16:13 GMT
>I have a class, which has a variable store the state of the class,
> e.g. isRunning
[quoted text clipped - 4 lines]
> seems getter (getXXX) is a normal way, but the method name seem to be
> dummy....

   Most tools I've worked with expect "get" as a prefix for non-boolean
fields, and "is" for boolean fields. If you want to be able to interoperate
with those tools, use "isRunning()" (lowercase 'i') rather than
"getIsRunning()".

   - Oliver
Andreas Leitgeb - 21 Feb 2007 16:28 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.