|
AcquisitionFor a much more powerful version of acquisition in Python, look at the discussion Jim Fulton presents in his ExtensionClasses.Acquisition is a version of inheritance based on an instance's environment (the instances it is a part of) rather than its genetics (its class hierarchy). These are what I think are cool mixin classes which allow variants of a new OOP inheritance model which Gil and Lorenz have called Acquisition in a recent presentation. Python is not well suited to their definition of Acquisition (which emphasizes things like compile-time type safety), but I've come up with two versions which I think could come in quite handy. If you don't know what acquisition is, here is the quick blurb I have in the docstring for Legacy.py:
mixin = Legacy # or Subscribing class Window(mixin): def __init__(self): self.color = 'blue' self.button1 = Widget() class Widget(mixin): def describe(self): print "Widget's color is", self.color >>> w = Window() >>> w.button1.describe() Widget's color is blueNote that a Widget is not a subclass of a Window, yet instances of it 'inherit' the color attribute. Note: These are mutually exclusive mixin classes. Use one or the other, but not both! Also, I don't think they'll work as is with other classes which override __getattr__, __setattr__ and __delattr__.
[Mon Jan 25 10:51:23 1999] |