Wednesday, April 22, 2009

APIs - parameter objects?

public void associateTrackedEntityWithIsUnique(GeoTrackedEntity trackedEntity,
GeoDevice geoDevice,
Date startDate,
boolean isUniqueTypedAssociated)
throws UnknownFeatureException;

The purpose of the above method is to associate the trackedEntity object with the geoDevice object. It would have been neater to specify these objects by their unique identifer, rather than requiring the whole object to be passed in. The latter causes code like this:


GeoDevice geoDevice = getGeoDevice(drvDriver.getBusUnitGuid(),deviceId);
GeoTrackedEntity te = getGeoTrackedEntity(drvDriver);
geoTrackedEntityApi.associateTrackedEntityWithIsUnique(te,gd,d,true);


We need to look up the two objects first, which is unnecessary since we already have the unique identifiers.

Another ugly code pattern is the fact that SS has created helper methods around the core api methods because they throw annoying exceptions. These exceptions should be runtime if there is nothing the coder can do about it.


private GeoTrackedEntity getGeoTrackedEntity(DrvDriver driver)
{
logger.debug("");

GeoTrackedEntity te;
try {
te = geoTrackedEntityApi.findTrackedEntity(driver.getGuid(), false);
} catch (UnknownFeatureException e2) {
te = addTrackedEntity(driver);
}

return te;
}

No comments: