extending a class without subclassing

graham.matthews@maths.anu.edu.au
18 Jan 1995 23:23:02 GMT

I was wondering if there is any way to add to the methods of an
existing class C without editing or copying the source for C, and
without building a sub-class of C. I really want some construction
like,

pseudo_class B(adds_to C):

def some_new_method():
...

B here is not a class, rather it is just a construction for grouping
together a set of extensions to an existing class.

The specific case in which I want to do this is with the Text
and ScrolledText classes in tkinter. At present we have

ScrolledText < Text

and I want to add some new functionality to both ScrolledText and
Text. So I want something like this,

ScrolledText < ExtendedScrolledText < ExtendedText < Text

where the Extended classes implement the new functionality. BUT
using sub-classing like this would mean that I would have to edit
or copy the tkinter library code, and I do not want to do this.

graham

--
                    Though the days come and go
                     There is one thing I know
                  I've still got the blues for you