[Zope3-Users] How to manually define an object's provided
interfaces?
Lennart Regebro
regebro at gmail.com
Mon May 29 07:31:03 EDT 2006
On 5/29/06, Frank Burkhardt <fbo2 at gmx.net> wrote:
> I'm going to write an alternative implementation of
> zope.app.file.interfaces.IFile . This implementation will automatically
> determine the mime type of the data it's containing.
>
> I would like to add a method that determines (guesses), if the current file
> object contains an image...
>
> isimage=(mimetype(self.data).split('/')[0] == 'image')
>
> ... and I want to dynamically make the object implement another interface ...
Ehhh. Really? I must say that I find that a very suspiscious way of
handling that problem. Rather I would use a factory that generates the
correct type of object (image or file) from the data.
> if isimage:
> IImage.provide(self)
> else:
> IImage.dontprovide(self)
>
> Unfortunately, there is no 'provide' method on interfaces :-( .
Of course, you don't want to make an interface dynamically be another
interface, that just doens't make any sense. You could probably do it
by making the OBJECT provide different interfaces dynamically.
> 2. Is it according to Zope-, Python-, ... philosophy ok to danymically implement
> interfaces depending on the inner state of an object?
Uhm. IMO, no, not unless you really, really have to.
--
Lennart Regebro, Nuxeo http://www.nuxeo.com/
CPS Content Management http://www.cps-project.org/
More information about the Zope3-users
mailing list