I have the following method in a java bean class -
private boolean saveReturnPart(List<WarningMessageVO> messages)
{
boolean ret;
// logic here determines if a Return Part should be saved and sets "ret"
variable
return ret;
}
The method basically returns true if a return part should be saved, false if
not - the problem is (and probably a very stupid question) what should i
name the method?
isSaveReturnPart() - doesn't sound right
saveReturnPart() - sounds like it's doing the actual save
shouldSaveReturnPart() - sounds right but is "should" the word to use?
is there a standard for this? - any suggestions?
thanks in advance
harry
Arved Sandstrom - 29 Jun 2008 12:32 GMT
>I have the following method in a java bean class -
>
[quoted text clipped - 23 lines]
>
> harry
'is' is the semi-standard prefix for boolean methods...that is, you see if
that'll work for you first. But 'has', 'can' and 'should' are also perfectly
acceptable, because they all imply a truth value.
Your last suggestion is fine - it expresses the desired idea exactly.
AHS
harry - 29 Jun 2008 12:48 GMT
>>I have the following method in a java bean class -
>>
[quoted text clipped - 31 lines]
>
> AHS
thanks for that Arved, jsut needed someone to give me a sanity check!
Patricia Shanahan - 29 Jun 2008 13:56 GMT
> I have the following method in a java bean class -
>
[quoted text clipped - 23 lines]
>
> harry
Of your ideas, I prefer "shouldSaveReturnPart". Personally, I would use
"doSaveReturnPart", but I think that is just a matter of taste.
Patricia
Daniel Pitts - 30 Jun 2008 16:09 GMT
> Of your ideas, I prefer "shouldSaveReturnPart". Personally, I would use
> "doSaveReturnPart", but I think that is just a matter of taste.
>
> Patricia
I disagree. While it is somewhat a matter of choice, its also a style of
communication.
To me, shouldFoo() implies a test to determine whether to call doFoo().
I would expect constructs like:
if (shouldFoo()) {
doFoo();
}
If only Java had allowed "?" as part of an identifier.
if (saveReturnPart?()) {
saveReturnPart();
}

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jean-Baptiste Nizet - 29 Jun 2008 13:59 GMT
harry a écrit :
> I have the following method in a java bean class -
>
[quoted text clipped - 19 lines]
>
> is there a standard for this? - any suggestions?
Hi.
If the method was a property accessor and should conform to the standard
JavaBeans naming conventions, the "is" prefix would be mandatory. I
would then choose a name like isReturnPartSaveNeeded(). But since this
is a simple method, which is private BTW, shouldSaveReturnPart is
perfect: it says exactly what themethod does.
JB.
> thanks in advance
>
> harry
Maarten Bodewes - 30 Jun 2008 00:32 GMT
> harry a écrit :
>> I have the following method in a java bean class -
[quoted text clipped - 28 lines]
> is a simple method, which is private BTW, shouldSaveReturnPart is
> perfect: it says exactly what themethod does.
I do think that getSaveReturnPart() would also be acceptable. I don't
use beans much, but maybe that's an advantage for questions like this.
Regards,
Maarten