biro said:
Lets say I have a class called Order and I want a method to cancel the
order. Would you call this
cancel() or cancelled()
?
Similarly,
authorise() or authorised()
What's the best style ?
If your methods change the state of the object, then a verb
seems appropriate. If it just interrogates the state of the object,
then use the adjectival form.
So for me
void cancel()
conveys something that actually cancels an order while
boolean cancelled()
returns a flag indicating if the order was cancelled, but
doesn't change the state of the object.
You might want to have both methods in a given class. Some
people seem to prefer something like isCancelled for
the second case, and sometimes that form may be clearer, but in
this case I wouldn't think it necessary.
Regards,
Tom McGlynn