[Python-3000] Abilities / Interfaces

Gustavo Niemeyer gustavo at niemeyer.net
Thu Nov 23 13:45:48 CET 2006


> > Consider 'iter()', for example, which can be viewed as adapting an
> > object to the "iteration interface" and returning an object
> > supporting iteration.
> 
> An architecture astronaut might view it that way, but
> I don't. To my way of thinking, iter(x) creates a new
> object that iterates over x. Calling it a form of
> adaptation just muddies things with uneccessary words.

FWIW, Phillip was pointing out the following similarity:

  >>> class IIterable(Interface): pass
  ... 
  >>> class IIter(Interface): pass
  ... 
  >>> class C(object):
  ...   interface.implements(IIterable)
  ...   def __iter__(self): return iter("foo")
  ... 
  >>> def adapt_to_iter(obj):
  ...     return obj.__iter__()
  ... 
  >>> component.provideAdapter(adapt_to_iter, (IIterable,), IIter)
  >>> 
  >>> iter(C()).next()
  'f'
  >>> IIter(C()).next()
  'f'

As mentioned before, the similarity doesn't hold for more
complex interface hierarchies.

-- 
Gustavo Niemeyer
http://niemeyer.net


More information about the Python-3000 mailing list