OO conventions
Steve Holden
steve at holdenweb.com
Sat Feb 4 10:09:05 EST 2006
Daniel Nogradi wrote:
[...]
> So after all, what is a 'factory' or 'factory function'?
The name is intended to be indicative: it's a function that makes things
- usually instances of some class.
As has already been pointed out. Image is a module from PIL, so
Image.open() is a function in that module. When you call it, it creates
an instance of some suitable image class (which will depend on the type
of the image) and returns that.
The point here is that Image.open() returns a
JpegImagePlugin.JpegImageFile instance for a .jpg file, a
GifImagePlugin.GifImageFile instance for a .gif file, and so on. It
wouldn't make sense to use a single class to represent all these
different image types, so Image.open() just creates an instance of the
appropriate class (whatever that may be, which will vary from call to
call) and returns that.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list