#496 Code Review of Enum Handling with if-else

Companies:
Sberbank
Themes:
JavaOOPCode Review

Perform a code review:

Java
class CodeProcessor {

    public void process(List<Code> codes) {
        for (Code code : codes) {
            if (CodeType.ITCP == code.getCodeType()) {
                doSmthngITCP();
            }
            else if (CodeType.TLS == code.getCodeType()) {
                doSmthngTLS();
            }
            else if (CodeType.OTHER == code.getCodeType()) {
                doSmthngOther();
            }
            else {
                doDefault();
            }
        }
    }

    private void doSmthngITCP() {
        System.out.println("Handling ITCP");
    }

    private void doSmthngTLS() {
        System.out.println("Handling TLS");
    }

    private void doSmthngOther() {
        System.out.println("Handling Other");
    }

    private void doDefault() {
        System.out.println("Handling Default Case");
    }
}

enum CodeType {
    ITCP, TLS, OTHER
}

class Code {
    private final CodeType codeType;

    public Code(CodeType codeType) {
        this.codeType = codeType;
    }

    public CodeType getCodeType() {
        return codeType;
    }
}

public class CodeProcessingApp {
    public static void main(String[] args) {
        List<Code> codes = Arrays.asList(
                new Code(CodeType.ITCP),
                new Code(CodeType.TLS),
                new Code(CodeType.OTHER)
        );

        CodeProcessor processor = new CodeProcessor();
        processor.process(codes);
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in