Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Fred Drake
On Tue, Jul 15, 2008 at 7:36 PM, Tim Cook <[EMAIL PROTECTED]> wrote:
> And in my Maildir example it implements what is defined in IMaildir but
> how does it 'provide' what is in IMaildirFactory?  Specifically the
> __call__ method.

The __call__ of a class is the default constructor (the standard
__new__/__init__ dance).  Static and class methods of the class can
also be used to support the interfaces of the class itself.

> So my continuing thick-headed questions is:  What does classProvides
> really mean from a practical standpoint?  Some kind of use case?

Well, it sounds like you've already identified it as a way to describe
the interface of the class (as a factory).  It's not unusual for code
using the component architecture to locate factories for objects by
looking up a utility that provides the factory interface.  That allows
some nice ways to re-use composition-based constructs.


 -Fred

-- 
Fred L. Drake, Jr. 
"Chaos is the score upon which reality is written." --Henry Miller
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Benji York
On Tue, Jul 15, 2008 at 7:27 PM, Fred Drake <[EMAIL PROTECTED]> wrote:
> On Tue, Jul 15, 2008 at 6:56 PM, Benji York <[EMAIL PROTECTED]> wrote:
>> When one says that a class *provides* an interface they're saying that
>> instances of that class *implements* the interface.
>
> Sorry, you got that backwards.  Instances provide the interfaces their
> class implements.

Darn, I always do that. ;)
-- 
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Tim Cook

On Tue, 2008-07-15 at 19:27 -0400, Fred Drake wrote:
> On Tue, Jul 15, 2008 at 6:56 PM, Benji York <[EMAIL PROTECTED]> wrote:
> > When one says that a class *provides* an interface they're saying that
> > instances of that class *implements* the interface.
> 
> Sorry, you got that backwards.  Instances provide the interfaces their
> class implements.

Thanks.

And in my Maildir example it implements what is defined in IMaildir but
how does it 'provide' what is in IMaildirFactory?  Specifically the
__call__ method. 

So my continuing thick-headed questions is:  What does classProvides
really mean from a practical standpoint?  Some kind of use case?

--Tim



-- 
**
Join the OSHIP project.  It is the standards based, open source
healthcare application platform in Python.
Home page: https://launchpad.net/oship/ 
Wiki: http://www.openehr.org/wiki/display/dev/Python+developer%27s+page 
**


signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Fred Drake
On Tue, Jul 15, 2008 at 6:56 PM, Benji York <[EMAIL PROTECTED]> wrote:
> When one says that a class *provides* an interface they're saying that
> instances of that class *implements* the interface.

Sorry, you got that backwards.  Instances provide the interfaces their
class implements.

> On the other hand, lets say you had an IFooFactory interface that only
> required that objects *providing* it be callable.  In that case a class
> Foo itself can *provide* the interface (because the class is callable).

This is right.


 -Fred

-- 
Fred L. Drake, Jr. 
"Chaos is the score upon which reality is written." --Henry Miller
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Tim Cook

On Tue, 2008-07-15 at 18:56 -0400, Benji York wrote:
> On Tue, Jul 15, 2008 at 6:31 PM, Tim Cook <[EMAIL PROTECTED]> wrote:
> 
> >> Note: classes *implement* interfaces, their instances *provide* them.
> >
> > ... and I am still confused about a use case for classProvides.
> 
> When one says that a class *provides* an interface they're saying that
> instances of that class *implements* the interface.
> 
> On the other hand, lets say you had an IFooFactory interface that only
> required that objects *providing* it be callable.  In that case a class
> Foo itself can *provide* the interface (because the class is callable).
> 
> Make sense?

Hmmm, not really.  I tend to be VERY applied so how about an example
from Zope?

==
class Maildir(object):
"""See `zope.sendmail.interfaces.IMaildir`"""

classProvides(IMaildirFactory)
implements(IMaildir)


class IMaildirFactory(Interface):

def __call__(dirname, create=False):
"""Opens a `Maildir` folder at a given filesystem path.

...


class IMaildir(Interface):
"""Read/write access to `Maildir` folders.

See http://www.qmail.org/man/man5/maildir.html for detailed format
description.
"""

def __iter__():
"""Returns an iterator over the pathnames of messages in this
folder.
"""

def newMessage():
"""Creates a new message in the `maildir`.
=

Now why wouldn't IMaildir just not inherit from IMaildirFactory instead
of from Interface?  If it did; what would be the effect of the
difference(s) in approach to the rest of the application?

Thanks,
Tim

  





-- 
**
Join the OSHIP project.  It is the standards based, open source
healthcare application platform in Python.
Home page: https://launchpad.net/oship/ 
Wiki: http://www.openehr.org/wiki/display/dev/Python+developer%27s+page 
**


signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Benji York
On Tue, Jul 15, 2008 at 6:31 PM, Tim Cook <[EMAIL PROTECTED]> wrote:

>> Note: classes *implement* interfaces, their instances *provide* them.
>
> ... and I am still confused about a use case for classProvides.

When one says that a class *provides* an interface they're saying that
instances of that class *implements* the interface.

On the other hand, lets say you had an IFooFactory interface that only
required that objects *providing* it be callable.  In that case a class
Foo itself can *provide* the interface (because the class is callable).

Make sense?
-- 
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Tim Cook

The purpose of this question is related to an earlier question I had
about using the best/correct schema field choice.  It was pointed out
that I should use 'Object' and set the schema to the interface of the
class(es) that I wanted that attribute to accept.  Since I did not point
out that all of the classes that I wanted an attribute to accept would
be descendants of that base class (and their interfaces) that is
probably where I misunderstood that I would need to use classProvides. 

On Tue, 2008-07-15 at 21:39 +0200, Markus Kemmerling wrote:
> An instance of a class provides not only the interface the class  
> declares to implement, but also all base interfaces of this  
> interface. In particular an instance that povides any interface, will  
> always provide 'Interface'.

... and that makes perfect sense.


> Note: classes *implement* interfaces, their instances *provide* them.

... and I am still confused about a use case for classProvides.

> You probably don't want to use 'classProvides' at all.  The  
> 'implements(IDvText)'  statement is enough for all instances of  
> 'DvText' to provide 'IDataValue'.

Barring any replies to the contrary; I will remove all the superfluous
classProvides calls. Since this makes sense to me and was my original
understanding.  Basically that interface inheritance acts just like
class inheritance. 

Thanks,
Tim



-- 
**
Join the OSHIP project.  It is the standards based, open source
healthcare application platform in Python.
Home page: https://launchpad.net/oship/ 
Wiki: http://www.openehr.org/wiki/display/dev/Python+developer%27s+page 
**


signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Markus Kemmerling


Am 15.07.2008 um 20:53 schrieb Tim Cook:


If interface B inherits from interface A and class B implements
interface B; do I need to explicitly state that class B provides
interface A?


An instance of a class provides not only the interface the class  
declares to implement, but also all base interfaces of this  
interface. In particular an instance that povides any interface, will  
always provide 'Interface'.



Concrete example:

class IElement(Interface):
 value = Object(
schema=IDataValue,
title=_(u"value"),
description=_(u"""Data value of this leaf."""),
required=False
)

class IDvText(IDataValue):

...


class DvText(DataValue):



implements(IDvText)
classProvides(IDvText)


The last line doesn't make any sense here.  As I tried to explain  
before, if a class declares to 'implement' an interface, all of it's  
instances will provide it, whereby 'classProvides' declares the  
*class itself* to directly provide the interface.


Note: classes *implement* interfaces, their instances *provide* them.

Will Element.value allow instances of DvText or do I need to change  
the

DvText classProvides call to:

classProvides(IDataValue,IDvText)


You probably don't want to use 'classProvides' at all.  The  
'implements(IDvText)'  statement is enough for all instances of  
'DvText' to provide 'IDataValue'.


Regards,
Markus Kemmerling
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Interface confusion (still)

2008-07-15 Thread Shailesh Kumar
Hi,

I believe not. In any case, implements, provides and such things are more
like indications of what is being supported by a class and they are not
enforced by runtime strictly.

I just tried following:

#

from zope.component import *
from zope.interface import *
from zope.interface.verify import *

class IA(Interface): pass

class IB(IA): pass




class B(object):
implements(IB)


verifyClass(IA, B)  #returns True
verifyClass(IB, B) #returns True
verifyClass(Interface, B) #returns True



class IC(Interface) : pass

#


Its usually a good idea to setup unit tests for testing these kind of
things.

With regards,
- Shailesh

On 7/15/08, Tim Cook <[EMAIL PROTECTED]> wrote:
>
> If interface B inherits from interface A and class B implements
> interface B; do I need to explicitly state that class B provides
> interface A?
>
> Concrete example:
>
> class IElement(Interface):
> value = Object(
>schema=IDataValue,
>title=_(u"value"),
>description=_(u"""Data value of this leaf."""),
>required=False
>)
>
> class IDvText(IDataValue):
>
> ...
>
>
> class DvText(DataValue):
>
> 
>
> implements(IDvText)
> classProvides(IDvText)
>
>
> Will Element.value allow instances of DvText or do I need to change the
> DvText classProvides call to:
>
> classProvides(IDataValue,IDvText)
>
> Thanks,
> Tim
>
>
>
>
>
> --
> Timothy Cook, MSc
> Health Informatics Research & Development Services
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> Skype ID == timothy.cook
> **
> *You may get my Public GPG key from  popular keyservers or   *
> *from this link http://timothywayne.cook.googlepages.com/home*
> **
>
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>
>
>
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Interface confusion (still)

2008-07-15 Thread Tim Cook
If interface B inherits from interface A and class B implements
interface B; do I need to explicitly state that class B provides
interface A?

Concrete example:

class IElement(Interface):
 value = Object(
schema=IDataValue,
title=_(u"value"),
description=_(u"""Data value of this leaf."""),
required=False
)

class IDvText(IDataValue):

...


class DvText(DataValue):



implements(IDvText)
classProvides(IDvText)


Will Element.value allow instances of DvText or do I need to change the
DvText classProvides call to:

classProvides(IDataValue,IDvText)

Thanks,
Tim





-- 
Timothy Cook, MSc
Health Informatics Research & Development Services
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
Skype ID == timothy.cook 
**
*You may get my Public GPG key from  popular keyservers or   *
*from this link http://timothywayne.cook.googlepages.com/home*
**


signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users