Extract Method
Problem: A method does too many things at once, mixing several concerns into one long block of code.
Solution: Move a cohesive chunk of the method into its own well-named method, then call that method from the original spot.
class Book {
void printDetails() {
System.out.println(title);
System.out.println(author);
System.out.println(isbn);
System.out.println(price);
}
}class Book {
void printDetails() {
printIdentity();
printPrice();
}
void printIdentity() {
System.out.println(title);
System.out.println(author);
System.out.println(isbn);
}
void printPrice() {
System.out.println(price);
}
}Diagram loads as you scroll.
Diagram loads as you scroll.