T
Tim Jowers
i repeatedly see this pattern:
{ TBaseType ret = TBaseType.Factory.newInstance();
try{
// start some call //
dbControl.deleteSearchLog(logId);
// after some call //
} catch(SQLException sqe)
{ // return error code
ret.setErrorCode( "1" );
ret.setErrorMessage( sqe.toString() );
Log(""); ...
}
return ret;
}
where I have a method or segment of code that is 90% identical except
for a line or a few lines. What pattern makes this easy to work with?
The only idea I have is to create a class that takes an object, method
name, and parameter array and makes the call. Is that the typical
solution? It seems very contrived and hard to work with versus just
typing the code like
dbControl.deleteSearchLog(logId);
And seems to totally break if I have several statements. Then I have
to make a new method to hold each of the statements and somehow pass
all the required parameters...
Thanks,
TimJowers
{ TBaseType ret = TBaseType.Factory.newInstance();
try{
// start some call //
dbControl.deleteSearchLog(logId);
// after some call //
} catch(SQLException sqe)
{ // return error code
ret.setErrorCode( "1" );
ret.setErrorMessage( sqe.toString() );
Log(""); ...
}
return ret;
}
where I have a method or segment of code that is 90% identical except
for a line or a few lines. What pattern makes this easy to work with?
The only idea I have is to create a class that takes an object, method
name, and parameter array and makes the call. Is that the typical
solution? It seems very contrived and hard to work with versus just
typing the code like
dbControl.deleteSearchLog(logId);
And seems to totally break if I have several statements. Then I have
to make a new method to hold each of the statements and somehow pass
all the required parameters...
Thanks,
TimJowers