8

I know there was a technical term for this. I'm just can't remember what it was.

If the title needs clarification, here is what I mean; If this is the old code:

Result foobar(Param1,Param2,Param3) {
  code that does abc
  code that does xyz
  code that does asdf
  more code that does something
}

and it's changed into:

SomeResult do_xyz(SomeParams) {
  code that does xyz
}
Result foobar() {
  code that does abc
  do_xyz(args);
  code that does asdf
  more code that does something
}
gnat
  • 20,543
  • 29
  • 115
  • 306
bitmask
  • 879

2 Answers2

21

Technical term for this is Extract Method

See http://www.refactoring.com/catalog/extractMethod.html

Turn the fragment into a method whose name explains the purpose of the method.

void printOwing() {
    printBanner();

    //print details
    System.out.println ("name:    " + _name);
    System.out.println ("amount    " + getOutstanding());
}

                                                                                                         http://www.refactoring.com/catalog/arrow.gif

void printOwing() {
    printBanner();
    printDetails(getOutstanding());
}

void printDetails (double outstanding) {
    System.out.println ("name:    " + _name);
    System.out.println ("amount    " + outstanding);
}
gnat
  • 20,543
  • 29
  • 115
  • 306
herby
  • 2,774
  • 1
  • 20
  • 25
8

The process itself is called Refactoring the code, and method is called Extract Method , and it is a good match for applying SRP (single responsibility principle) to the code.

Yusubov
  • 21,498