Results 1 to 6 of 6
Thread: java-Encapsulation
- 01-05-2009, 08:50 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 4
- Rep Power
- 0
- 01-05-2009, 09:21 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
The type of the variable is doesn't matter at all. You can use get/set method or any other custom name for a method.
- 01-05-2009, 10:16 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 68
- Rep Power
- 0
It's a matter of preference, I personally would use getIsVariableName/setIsVariableName
- 01-05-2009, 10:59 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's better what ever more descriptive name convention use.
- 01-05-2009, 12:20 PM #5
By far the most common convention is to use set/is for booleans and set/get for all other types.
getIs/setIs appears horribly contrived.
db
edit
In addition, this is part of the Java Beans specification. Click the link on
API Specifications for JavaBeans
(Requires login to the Sun Java Developers Community)
Section 8.3.2 says:
8.3.2 Boolean properties
In addition, for boolean properties, we allow a getter method to match the pattern:
public boolean is<PropertyName>();
This “is<PropertyName>” method may be provided instead of a “get<PropertyName>” method,
or it may be provided in addition to a “get<PropertyName>” method.
In either case, if the “is<PropertyName>” method is present for a boolean property then we will
use the “is<PropertyName>” method to read the property value.
An example boolean property might be:
public boolean isMarsupial();
public void setMarsupial(boolean m);
Or see the JavaBean Example on
JavaBean - Wikipedia, the free encyclopediaLast edited by DarrylBurke; 01-05-2009 at 12:40 PM. Reason: Added information
- 01-05-2009, 09:05 PM #6


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks