I have a method that performs several tasks. It is part of the business logic of the application, but it is poorly read due to the many if-then and try-catch blocks and the many log calls.
public class MyClass { boolean createReport, sendReport, warnIfErrors; public void archiveAll() { if (createReport) {
The idea is to move tasks to special methods and have an archiveAll method that you can understand at a glance:
public void archiveAll() { doCreateReport(); doSendReport(); doWarnIfErrors(); }
But this raises two problems:
- if all methods use a local variable, I will move it as a class field, but this is not a good design
- I want to move the
if (createReport) test to the doCreateReport method too, because part of the complexity stems from the tests that are executed. This makes helper methods poorly cohesive, though.
source share