OO conventions

Tim N. van der Leeuw tim.leeuwvander at nl.unisys.com
Thu Feb 2 08:50:10 EST 2006


Daniel Nogradi wrote:
> >
> > In this case, Image seems to be a python module, with the open function
> > defined, PIL's Image is not a class.
> >
>
> Thanks for the enlightening remarks, especially this last one, indeed,
> it's not a class.

Actually, this way of creating a class instance is good OO practice in
many places: The Image.open() method acts as a factory-function for
creating Image objects.
You don't know, until you inspect the return value, if the created
object is actually an instance of class Image or something which just
happens to behave like one...
It could for instance be a sub-class of Image, JpegImage, if that
better suits the class library designers.
In general, factory-functions allow greater uncoupling between
interface and implementation.

Regards,

--Tim




More information about the Python-list mailing list