Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
}
share|improve this question
    
I'd have called it 'Tidying up'. I can't believe someone decided to call this something special, they must have needed filler for their book. –  James Jul 2 '12 at 23:15
    
@James: 'tidying up' is a lot more generic. It makes sense to give things that you need to talk about often names, so you can talk about them more efficiently. That is the only reason for patterns. –  bitmask Jul 2 '12 at 23:25

2 Answers 2

up vote 21 down vote accepted

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);
}
share|improve this answer
4  
extraction -- that's it! –  bitmask Jul 2 '12 at 19:22
    
Extract Method. You should check out Design Patterns. –  Larry Hector Jul 2 '12 at 20:04
9  
@LarryHector: I'm not sure it's (GoF) Design Patterns. There is thing called Template Method there that is a bit similar, and of course DP is fundamental read, but Extract Method as well as lots of other refactorings are in fact in other piece of literature and that is Martin Fowler's Refactoring. –  herby Jul 2 '12 at 20:16
1  
@herby: You are correct, it is defined in Fowler's Refactoring, thanks for the correction. There is also a good section on the how/why of many of the refactoring methods in Michael Feathers' Working with Legacy Code. –  Larry Hector Jul 3 '12 at 12:37

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.

share|improve this answer
    
Is "Refacturing" a typo? (honest question!) –  bitmask Jul 2 '12 at 20:06
    
@bitmask It most probably is –  mcwise Jul 2 '12 at 20:07
    
Yes, it is a typo, as it may seem from the links, it was intended to be "Refactoring" –  Yusubov Jul 2 '12 at 20:08
5  
Refactoring is less specific. Extract Method is one of many, many kinds of refactoring. And neither one is implicitly related to SRP, although that is one of many reasons you might want to refactor. –  pdr Jul 2 '12 at 20:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.