I'm trying to use the decorator pattern in a program I'm developing. I want to create a decorator object that works like the object it's decorating except for a few functions. However, I'd rather not hard-code all the identical functionality from the decorated object into the decorator object. Is there a way I can intercept all the attribute and function requests for the decorator and delegate them to the decorated object? Here's some example code:
class Decorator: > def __init__(): > self.decorated = Decorated() > > def newFunction(): > # Do something > pass > > def interceptRequests(request): > return self.decorated.request() > > class Decorated: > def __init__(): > self.variable = 10 > > def oldFunction(): > # Do something > pass I want to be able to do something like this: objectA = Decorator() > objectB = Decorated() > assert objectA.oldFunction() == objectB.oldFunction() # No error > Is it possible (without inheritance)? -- Evan Kroske http://welcome2obscurity.blogspot.com/ The code, comments, and challenges of a novice software developer desperate for attention.
-- http://mail.python.org/mailman/listinfo/python-list