Contractive Delegation

See http://flea.sourceforge.net/ContractiveDelegation.pdf


Well-factored code has lots of little tiny functions (see LotsOfShortMethods).

Just what do these two-line functions actually do?

Typically, they contract their input by making it more specific. Then they delegate these specific data to a delegatee.

For example, this takes a fileName, augments it with the current document, then passes them both into the File system delegatee:

    def save(fileName)
        string = get_chars(0, get_length)
        File.open(fileName, "w").write string
    end

Contrast with the PassTheBuckAntipattern.

--PhlIp (via the couth kempt and shevelled JohnSarkela)

Another way to put it is that every tiny method must do something that solves one tiny part of the problem, and delegates the remaining part of the problem to other methods. You can avoid the PassTheBuckAntipattern by making sure every method makes some sort of simplifying transformation on the input before passing it to other methods, or makes some sort of simplifying transformation on the output of other methods before returning to the caller.

See http://www.xpsd.com/RefactoringDemo , ComposedMethod.


EditText of this page (last edited June 19, 2008) or FindPage with title or text search