On Sun, 2003-02-02 at 06:05, Fionn Behrens wrote:
> On Fre, 2003-01-31 at 22:53, Ian Bicking wrote:
> > On Fri, 2003-01-31 at 12:31, Fionn Behrens wrote:
> > > I have one problem left, however. 
> > > [...]
> 
> > You can still put it in a global, but you need to do locking to handle
> > this.  I'd personally use a combination of my own ParamFactory and
> > Persist modules, which are primitive but effective.  I think it would go
> > something like:
> > 
> > class _Image(PersistMixin):
> [...]
> 
> This looks very similar to what I alredy have.
> 
> > Image = ParamFactory(_Image)
> 
> So this factory has to be the needed part that is only there once. Since
> I am not quite accustomed to factories (admittedly all I know about them
> is that I already read the term some time on this list) my problem has
> not yet vanished but shifteed to: where should that factory class go to
> be instantiated only once?

Essentially instead of Image being a class, it is a function that has
access to a cache of instances.  So anytime you call Image with the same
tuple of parameters you'll get the cached instance if possible.  (As a
result you can't use default parameters or even keywords -- a fancier
ParamFactory could probably deal with that, but this one can't.) 
Anyway, just use the Image factory everywhere you were using the class,
and _Image just lives behind the scenes.

A "factory" just means something that returns objects, but in a more
flexible manner than a class.  In this case it creates objects on
demand, or returns existing objects if available.  The servlet factories
in Webware also do some object initialization in addition to pooling.

With Python 2.2 you can also do this same stuff with the __new__ method,
which doesn't require a separate factory (though you'd probably want a
mix-in, since the basic concept is reusable).  I don't like the way
__new__ was implemented, though -- it actually requires more change to
your code than does the factory.

-- 
Ian Bicking           Colorstudy Web Development
[EMAIL PROTECTED]   http://www.colorstudy.com
PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to