OO conventions
Daniel Nogradi
nogradi at gmail.com
Sat Feb 4 09:00:29 EST 2006
> > 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.
> >
>
> From all the enlightening replies it seems to me that my next task
> should be to look into what 'factory functions' are. Whenever I've
> seen the word 'factory' I just skipped it, knowing that if I really
> need to know what it is, I'll come back to it later. Apparently it's
> just about time, thanks all for the comments.
>
I've been looking around for what factory functions are, but honestly
I've been grepping and googling but couldn't find a clear definition
of the concept of 'factory', 'factory function' or 'class factory'. As
I've said I'm relatively new to OOP and the reason is that for too
long I thought that there is no need for it, ordinary C will do. But
once the concepts became clear, it started to become useful. That's
why I'm not particularly interested in examples and code snippets but
rather the general ideas and their definitions, but for these
'factories' I really couldn't find a clear explanation anywhere only
how to use them, example code and such. Perhaps because I was only
searching in the context of Python.
So after all, what is a 'factory' or 'factory function'?
More information about the Python-list
mailing list