[PEAK] PyProtocols --
Gabriel Jägenstedt
gabriel.j at telia.com
Mon Feb 16 09:14:27 EST 2004
On Sun, 15 Feb 2004 21:35:28 -0500
"Phillip J. Eby" <pje at telecommunity.com> wrote:
> At 11:06 PM 2/15/04 +0100, Gabriel Jägenstedt wrote:
> >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)
> >
> >"""
>
> It would be most helpful if you could replace A, B, and C with the
> names and descriptions of the real-world things you're trying to do.
> Then I could perhaps offer suggestions. At the moment, I don't
> understand what it is you're trying to accomplish in your program.
>
> Now, I'm going to make a guess that by text games, you mean
> interactive fiction, and I'm going to further guess that maybe you're
> trying to have a way to have objects respond to various actions. And,
> that maybe objects have properties like weight or size that affects
> their ability to be carried, lockedness for doors, and so on. And
> perhaps you'd like for command verbs (e.g. "pick up") to adapt the
> target object to an "ICarryable" protocol, and ask if it can be
> carried. And, provide a default implementation for ICarryable that
> says the object can't be picked up.
>
> Is this anything like what you're asking about? Please describe the
> behavior you're trying to obtain, and focus less on how you're doing
> the classes right now. (Because if what you have now doesn't work,
> that will just get in the way of us figuring out what *will* work.)
>
> Thanks.
>
Sure ok.. sorry bout that.
Yo're sure not far of the mark.
The project in mind is PUB -- Python Universe Builder
As it's meant to be set up I should have some basic classes, first we
have BaseThing or Noun. What it does is set up the object into existence
giving it a name and putting it into a place. As this is the most basic
of things the basic behaviour of all nouns is going to reside here
second we have extentions of Noun. In my private example I am using
Edible to have an Idea of what I'm doing, but we can just as well use
Carriable or other names for that matter. I hadn't really thought about
exactly to what extent I want these to work. I really like the idea with
having adaptor factories do the work of supplying the can't be carried
or eaten or whatnot.
--
I myself thought at first that making this work would require making
the extensions add themselves to objects when I initialize a new object
maybe it really does though if I want methods and variables to be
available between different Interfaces of a Noun. Say in some cases
have ILockable affect the possibility to open a Noun like door. But
we could just as easily have a lock making a book impossible to read.
In escence I wish that in extensions there is the possibility to run
various functions. PreObj: checks that everything is ok before making
the move to actually change the Noun, location, size and whatnot.
PostObj: prints output and does the actual work.
These are the two main methods that most Nouns need to change.
Furthermore each extension should have private methods that do work on
it's behalf. like ILightsource would have methods to compute light and
if it can be seen and vorious other things.
I can't explain more at the moment have to go to work.
thanks anyhow
--
//gabriel - a true believer
More information about the PEAK
mailing list