[Python-Dev] Re: tarfile module (update)

Fredrik Lundh fredrik@pythonware.com
Wed, 27 Nov 2002 10:08:11 +0100

Gustavo Niemeyer wrote:

> > There is a two-level public API to tarfile. The low-level API which =
> > the TarFile class with its __init__(), and the high-level API which =
> > the module-level open() function.
> [...]
> Ok, but I still belive that the default constructor should be the most
> common used interface, just like most (all) of the standard library.

using factory functions to create objects representing external
entities is an extremely common pattern.

in the Pythobn library, this pattern is used in aifc, anydbm, audiodev,
dbhash, dumbdbm (and all other dbm modules), fileinput, gettext,
gopherlib, gzip, imghdr, optparse, popen2, shelve, sndhdr, socket,
sunau, sunaudio, tempfile, tokenize,  just to name a few.

to figure out *why* it's a good idea to use a factory function, think
as a user.  or as a library maintainer.

</F> (yes, PIL's using it too)