Fredrik Lundh wrote:
> Nicola Musatti wrote:
[...]
> > What is important to me is to keep your get_initial_data() function
> > outside Klass if it's task is non trivial, e.g. it has to interact with
> > the OS or a DB.
>
> why ?
Separating the internal logic of an application from its interaction
Fredrik Lundh wrote:
> Nicola Musatti wrote:
>> What is important to me is to keep your get_initial_data() function
>> outside Klass if it's task is non trivial, e.g. it has to interact with
>> the OS or a DB.
>
> why ?
In order to simplify testing.
--Scott David Daniels
[EMAIL PROTECTED]
--
ht
> > So after all, what is a 'factory' or 'factory function'?
>
> A brief explanation in Python terms is at
> http://www.aleax.it/ep03_pydp.pdf -- "pages" (slides) 37-44 (the rest of
> the presentation is about an even more fundamental design pattern,
> "template method"). A far more extensive essa
Nicola Musatti wrote:
> > def factory(info):
> > k = Klass()
> > data = get_initial_data(info)
> > k.set_data(data)
> > return k
> >
> > to:
> >
> > def factory(info):
> > data = get_initial_data(info)
> > return Klass(data)
> >
> > What would be the value of doing the init
I V wrote:
> Nicola Musatti wrote:
[...]
> > Factory functions (or classes) are there to solve this problem and
> > still allow a clean separation of concerns. Although instances of Klass
> > are created uninitialized, they only live in this state within their
> > factory and only reach trhe outsi
Alex Martelli wrote:
> As you see, static methods have a small extra lookup cost (a couple
> hundred nanoseconds on my oldish laptop);
I would've expected the opposite effect...I guess the runtime
considers instances more active than the static portion of
a class.
> "Premature
> optimization is
Blair P. Houghton <[EMAIL PROTECTED]> wrote:
...
> > It is (search for 'staticmethod' and 'classmethod'). But there's not
> > much use for 'static methods' in Python - we usually just use plain
> > functions ('classmethods' are another beast - much more useful than
> > staticmethods)
>
> Does i
Daniel Nogradi <[EMAIL PROTECTED]> wrote:
...
> So after all, what is a 'factory' or 'factory function'?
A brief explanation in Python terms is at
http://www.aleax.it/ep03_pydp.pdf -- "pages" (slides) 37-44 (the rest of
the presentation is about an even more fundamental design pattern,
"templat
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 m
> > 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
bruno at modulix wrote:
> Blair P. Houghton wrote:
> > So Image.open(filename) seems right as a factory function that opens
> > the file, figures out what it really is, constructs the appropriate
> > subclass object (likely by passing a string to the constructor, e.g.,
> > JPGImage(filename)), and
Nicola Musatti wrote:
> I don't think this is all there is to it. Even though a class such as
> Image might not have a sensible default, initial state it still might
> not be reasonable to burden it with the ability to collect the
> information needed to reach such an initial state. To put it it an
Blair P. Houghton wrote:
(snip)
> So Image.open(filename) seems right as a factory function that opens
> the file, figures out what it really is, constructs the appropriate
> subclass object (likely by passing a string to the constructor, e.g.,
> JPGImage(filename)), and returns the object via th
Steven D'Aprano wrote:
[...]
> If a class has a natural, obvious default state (e.g. a mutable string
> class might start off empty, a mutable int class might start off as zero,
> a binary tree might start off as an empty node with no children) then it
> makes sense to initialise the class, then a
On Thu, 02 Feb 2006 17:00:26 -0800, Blair P. Houghton wrote:
> Image would be a superclass to JPGImage, BMPImage, PNGImage, etc...
>
> But which to use could only be determined AFTER opening the file,
> because "file.jpg" doesn't have type JPG, it has type string and
> semantic value "maybe a jpe
Image would be a superclass to JPGImage, BMPImage, PNGImage, etc...
But which to use could only be determined AFTER opening the file,
because "file.jpg" doesn't have type JPG, it has type string and
semantic value "maybe a jpeg file or maybe something misnamed as a jpeg
file".
So Image.open(filen
> > > 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
Magnus Lycka <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> >>And now, at long last, the image object actually is an image. So why make
> >>this a two step process? Whatever the Image() initialization does, why
> >>can't it be done automatically
Alex Martelli wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>And now, at long last, the image object actually is an image. So why make
>>this a two step process? Whatever the Image() initialization does, why
>>can't it be done automatically when you read the file?
>
> "Two-step construct" (
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> > image = Image( )
>
> Now you have an "image" object. What is it?
>
> Answer: it isn't an image at all, not in the plain English sense. (Or if
> it is, it is an arbitrary "default image" picked by the class designer.)
No doubt (presumably some kind o
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
On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote:
> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natur
Terry Hancock wrote:
> What Lundh is modeling this on is not standard OOP thinking,
> but rather the standard way of opening files in Python.
>
> Or you could say he's using a "factory function".
"open" is a factory function, and it picks the right class based
on the file you're opening.
anyone
On Wed, 1 Feb 2006 23:40:37 +0100
Daniel Nogradi <[EMAIL PROTECTED]> wrote:
> I'm relatively new to object oriented programming, so get
> confused about its usage once in a while. Suppose there is
> a class Image that has a number of methods, rotate, open,
> verify, read, close, etc. Then to use th
>
> 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.
--
http://mail.python.org/mailman/listinfo/python-list
Daniel Nogradi wrote:
> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natural guess would be to have something l
Daniel Nogradi wrote:
> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natural guess would be to have something l
On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote:
> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natur
On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote:
> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natur
29 matches
Mail list logo