Hello all,
I have some relatively large legacy method that I would like to refactor. It fits "Bulleted method" type as specified in Michael Feathers' "Working Effectively With Legacy Code" and thus it could be split in several sequential methods in rather straight-forward way . But each of its sequential steps outputs some log message and forming that message requires much more data than for the step itself. So when I try to extract method, I end up with method having, say, 6 parameters. If I had removed those log statements I would have method with only 1 parameter. So I effectively cannot refactor anything. And I'm not allowed to just drop log statements.
A part of method looks like that:
// much of code before
Device device = getDevice(deviceID);
boolean isFirstRegistration = false;
if (device == null) {
/*logger.trace(
"DeviceId", deviceID,
"ADM", adminCode,
"Phone", clientData.getPhone()
);
logger.info("First registration of the device. Device ID - " + deviceID);*/
isFirstRegistration = true;
} else {
/*logger.trace(
"DeviceId", deviceID,
"ADM", adminCode,
"Phone", clientData.getPhone()
);
logger.info("Device ID - " + deviceID
+ " has been previously registered by adminCode: "
+ device.getAdminCode());*/
}
// much of code after
As you see, commented out logging statements. In this case I can extract method boolean isFirstRegistration(String deviceId)
. But when they are uncommented, signature bloats up to boolean isFirstRegistration(String deviceId, String adminCode, ClientData clientData)
. And that is not the most extreme case, just one from the first glimpse. Have you any ideas how should I refactor such method?