[PEAK] PyProtocols --

Gabriel Jägenstedt gabriel.j at telia.com
Sun Feb 15 17:06:03 EST 2004


I've been looking into pyprotocols over the last week or so.
I'm working on a textinterpreter for textgames, written in python and
I've found I can't really implement all the object behaviour I want
yet. What I'm looking for is something like multiple inheritence.
I want to do this:

class A:
    """ This is a class that all objects are meant to inherit from
It is most likely here I want to have the code to adapt other classes"""

class B:
    """A class that provides several methods and variables that extend
the functionality of class A. I could most likely use inheritence to do
this, somehow it doesn't seem right though. Using adaption it would
be possible to have different adapters for differnt kinds of objects
That I like"""

class C:
    """Here is an actual object class. It inherits from class A and also
wishes to add the functionality of class B. As I said I wish it to
happen in class A. All this class should need to do is:

class c(A):

addon = B (or IB if we are talking interfaces)

"""

I have code for some of this what I do need is a
good way to actually add B to C. All I've tried so far hasn't worked to
it's full extent.

Moreover and most importantly, all methods should be callable as if they
were really a part of the new class. This I never managed.

I've been discussing this with another developer on the project, David
Murray, He pointed me at PEAK as he was part of it aswell, and more
particulary at protocols.

In most respects I'm interested, now I just want to know if what I want
can be done and most importantly how. I haven't found much good
documentation on this. I need to know what I need in each kind of class
(A, B, C)
I figure I'll be using advice in B atleast and adapt in A but I'm not
certain about the details.
Would it be best to make A into a protocol in some way?
or should I use ClassType -- this didn't seems to work when I tried.

Thanks in advance. I don't mind reading if I can get pointed in the
right direction =)


-- 
//gabriel - a true believer



More information about the PEAK mailing list