callable classes

John Roth newsgroups at
Sat Dec 27 23:26:16 CET 2003

"Duncan Smith" <buzzard at> wrote in message
news:bshtlg$m1r$1 at
> I recently started to rewrite a class and decided to take a bunch of
> methods and put them in a separate callable class.  (They're all what I
> would call pointwise operations on pairs of instances, they raise
> for identical reasons, and they all return a new instance).  It seemed
> a good idea at the time, but now I'm not so sure.  So my very general
> questions are:
> Is this a reasonable use for a callable class?
> In what circumstances are callable classes particularly useful?  (Maybe I
> haven't racked my brains long enough.)

Function Objects (which is what the GoF patterns book calls
these things) are useful whenever you need a function that
requires long term persistant parameter storage. You can
initialize one with the parameters, and then use it many times
without the various callers having to remember the parameters
and pass them to it each time.

Another use is controlling visibility. In this use, it's somewhat
similar to a proxy, except that you don't have to remember the
name of the method to call; you just call the object.

John Roth

> Cheers.  TIA.
> Duncan

More information about the Python-list mailing list