#396 Removing Duplicate Logic

Companies:
Aston
Themes:
JavaOOPCode Review

Resolve the problem of duplicated logic:

public class SomeClass {

    public void someMethod() {
        System.out.println("do something 1");
        System.out.println("do something 2");
        SomeUtilityClass.doSomething();
        System.out.println("do something 3");
        System.out.println("do something 4");
    }

    public void someAnotherMethod() {
        System.out.println("do something 1");
        System.out.println("do something 2");
        SomeUtilityClass.doAnythingElse();
        System.out.println("do something 3");
        System.out.println("do something 4");
    }

    static class SomeUtilityClass {

        static void doSomething() {
            System.out.println("do something");
        }

        static void doAnythingElse() {
            System.out.println("do anything else");
        }
    }
}

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