Sobes.tech
Junior — Senior

Refactoring the report generation method

livecode

Task condition

The myBusinessLogic method receives an inputData object and, depending on its type (CUSTOMER, NONE_CUSTOMER, VIP), constructs a Report object. It is required to rewrite the method to eliminate duplication, improve readability, and prepare it for further extension.

class SuperService {
    public Report myBusinessLogic(InputData inputData) {
        Report report;

        if (inputData.getType().equals("CUSTOMER")) {
            report = doWorkWithData(inputData);
        } else if (inputData.getType().equals("NONE_CUSTOMER")) {
            // 20 lines of code
            report = result;
        } else if (inputData.getType().equals("VIP")) {
            // 40 lines of code
            report = result;
        }

        return report;
    }
}