I always have trouble figuring out if I should name a certain method starting with getSomething
versus findSomething
.
The problem resides in creating helpers for poorly designed APIs. This usually occurs when getting data from an object, which requires the object as a parameter. Here is a simple example:
public String getRevision(Item item) {
service.load(item, "revision");
// there is usually more work to do before getting the data..
try {
return item.get_revision();
}
catch(NotLoadedException exception) {
log.error("Property named 'property_name' was not loaded", exception);
}
return null;
}
How and why to decide between naming this method as getRevision()
or findRevision()
?