logging - Log statements prevent refactoring: how to help this? -
I have some relatively large legacy method that I want to reflector. This "bulleted method" type fits into "effectively working with the heritage code" referred to as Michael Wings, and thus it can be divided into direct sequences in many sequential ways. But each of its sequential steps produces some log messages, and to create that message, more data is required than that step, so when I try to remove the method, I say, the 6-parameter method If I had removed those log status then I would have only one method with 1 parameter. So I can not effectively refact anything. And I just do not have permission to leave log statements.
A part of the method looks like this:
// Device device = getDevice (deviceID) before much device; Boolean is First Registration = Wrong; If (device == faucet) {/.logger.trace ("DeviceId", deviceID, "ADM", adminCode, "phone", clientData.getPhone ()); Logger.info ("Device's first registration device ID -" + deviceID); * / IsFirstRegistration = true; } Else {/.comlogger.trace ("DeviceId", deviceID, "ADM", adminCode, "Phone", clientData.getPhone ()); Logger.info ("Device ID -" + deviceID + "is first registered by adminCode:" + device.getAdminCode ()); As a lot of code, you see, commenting on logging statements. In this case I can extract the method boolean isFirstRegistration (string device id)
. But when they are unconnected, signatures for Boolean Blocks First Registration (String Device ID, String AdminCode, Client Data Client Data)
. And this is not the most extreme case, the first glimpse is just one. Do you have any idea how should I refactor this kind of method?
Turn on logging in the Sprout class helper class and feed it to all the data, because it is required.
Update: By using the presented instance variable, for example, myLogger.setDevice
I will; Similarly logar log methods such as trace divis admin code and androphone ()
and logfest registration ()
for adminCode, clientData, etc., where it uses its image variables Wherever the variables change, feed them again on the loozer. Now, logger passes in ways that you can find out, as well as new parameters (but no longer) require any parameters directly, and what is required from your logar removed method.
In addition, if it is starting to look like your logger then your method is very intimate, alternatively the method must be removed in a new category and some local variables change in the example variable Must do; So the logger could instead ask the new class for the values rather than catching them, but as an assistant assistant, the logger class is probably a small, less effective, refactoring. Whether it is good or bad it depends on where you want to go with it.
Comments
Post a Comment