Composed Method

This is a pattern from SmalltalkBestPracticePatterns by KentBeck:

Divide your program into methods that perform one identifiable task. Keep all of the operations in a method at the same level of abstraction. This will naturally result in programs with many small methods, each a few lines long.

When you use ExtractMethod a bunch of times on a method the original method becomes a ComposedMethod.

ComposedMethod is NOT a synonym for ExtractMethod.

So the key difference is keeping all the operations in a method at the same level of abstraction? I can see where that might involve more than just a simple method refactoring. You might even generate whole new classes.

ComposedMethod then would be what you have after the code has been refactored mercilessly, whether the refactorings are ExtractMethod, ExtractClass, something else or some combination thereof.

On loose rule of thumb I've heard regarding this is that: If your description of what the method does uses the word "and" [at the top level], then it's doing two things (the two clauses the "and" links) and ought to be decomposed.

See: ContractiveDelegation, MethodObject


EditText of this page (last edited August 7, 2014) or FindPage with title or text search