#396 Removing Duplicate Logic
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
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor