| WritingAdaptors |
UserPreferences |
| The PEAK Developers' Center | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents |
Taken from the mail list thread http://www.eby-sarna.com/pipermail/peak/2004-March/001356.html:
Adapting takes an input object, and returns the object if it provides the desired protocol. If the input object does not provide the protocol, a lookup takes place to find an adapter function that will convert the object or create a wrapper to adapt it.
From a user example:
class IEdible(Interface):
"""Implements an edible behaviour on objects"""
def __init__():
"""a number of attributes that should be enabled in child"""
def PreObj(self, cmd=''):
"""returns a cmd'string'"""
class Food:
advise(instancesProvide = [IEdible])
def __init__(self, pNames=''):
self.id = 12
def PreObj(self, cmd=''):
print 'hurray'
adapt(IEdible, Food)
Food is a class. It does not provide IEdible, and you have not defined any adapters from it to IEdible.
However, you have declared that instances of Food provide IEdible. So this:
adapt(IEdible,Food())
will return you the Food instance you passed in.