[Python-3000] prototype OO?

Jim Jewett jimjjewett at gmail.com
Thu May 11 20:19:10 CEST 2006


On 5/11/06, tomer filiba <tomerfiliba at gmail.com> wrote:

> class myFrame(derive_of(c.modules.wx.Frame)):
>     ...

> c.modules.wx.Frame is a proxy (instance) to a remote type, so you can't
> derive from it directly. therefore, derive_of is

> def derive_of(proxy_type):
>     class cls(object):
>         def  __getattr__(self, name):
>             return getattr(proxy_type, name)
>     return cls

> which basically means that when the attribute doesn't belong to the
> instance of local class, it is queried for at the remote class. but it doesnt
> work, because the method checks for the instance's type.

There are languages (Self; I think even javascript) whose OO is based
on Prototypes rather than classes.  If an object doesn't have the
attribute/method, then check its prototype (and so on recursively).

When I have to emulate this in python (or Java), I just try to shove
all my logic into classmethods, and use at most a singleton instance.

Proxies are certainly the perfect example of something where you would
want a "just like X, except" object, and would prefer to be able to
use instances as the prototype.

I don't think prototype OO should replace the current form, but it
might be worth adding, even in Python 2.X.  Do you have a proposed
implementation, or even a proposed syntax?

-jJ


More information about the Python-3000 mailing list