Log in or register to vote.

Acquisition

Acquisition is a mechanism that allows objects to obtain attributes from the containment hierarchy they're in.

.. contents::

Introductory Example
====================

Zope implements acquisition with "Extension Class" mix-in classes. To
use acquisition your classes must inherit from an acquisition base
class. For example::

>>> import ExtensionClass, Acquisition

>>> class C(ExtensionClass.Base):
... color='red'

>>> class A(Acquisition.Implicit):
... def report(self):
... print self.color
...
>>> a = A()
>>> c = C()
>>> c.a = a

>>> c.a.report()
red

>>> d = C()
>>> d.color = 'green'
>>> d.a = a

>>> d.a.report()
green

>>> a.report() # raises an attribute error
Traceback (most recent call last):
...
AttributeError: color

The class ``A`` inherits acquisition behavior from
``Acquisition.Implicit``. The object, ``a``, "has" the color of
objects ``c`` and d ...

0
Author:
Zope Corporation and Contributors
Links: