title: Avoid code duplication on child classes of an abstract class
body: <p>I'm working on an old Struts application which has an abstract action to create Excel exports by filling Excel template files. </p>
  
  <p>Each Excel export action extends this parent class and adds its own implementation for filling the Excel template and defines its own template and output filename.</p>
  
  <pre><code>public abstract class ExcelExportAction extends BaseAction {
      protected abstract String getInputFilename();
      protected abstract String getOutputFilename();
      protected abstract HSSFWorkbook modifyWorkbook(HSSFWorkbook workbook, HttpServletRequest request);
  
      @Override
      protected final ActionForward run(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
      throws Exception {
  
          Workbook workbook = new Workbook(getInputFilename());
          workbook = modifyWorkbook(workbook, request);
          addWorkBookToResponse(workbook, getOutputFilename());       
  
          return null;
      }
  ...
  }
  </code></pre>
  
  <p>Implementations are looking like this and this is where the code duplication is "warned" by SonarQube:</p>
  
  <pre><code>public class BudgetReportExcelAction extends ExcelExportAction {
      private static final String INPUT_FILENAME = "Report-Budget-Template.xls";
      private static final String OUTPUT_FILENAME = "Report-Customerbudget.xls";
  
      @Override
      protected String getInputFilename() {
          return INPUT_FILENAME;
      }
      @Override
      protected String getOutputFilename() {
          return OUTPUT_FILENAME;
      }
      @Override
      protected HSSFWorkbook modifyWorkbook(HSSFWorkbook workbook, HttpServletRequest request) {
          /* modify the workbook */
          return workbook;
      }
  }
  </code></pre>
  
  <p>Any ideas how to avoid the duplication?</p>