Progress on missing features?

Alex Martelli aleaxit at yahoo.com
Wed Aug 15 14:53:18 EDT 2001


"John Roth" <johnroth at ameritech.net> wrote in message
news:tnlc2pecai5bb4 at news.supernews.com...
> I'd definitely like to see the interfaces. Class methods I can
> take a pass on; from a pragmatic viewpoint, I just put them
> in the module, and it works fine.

For the equivalent of C++'s static methods, yes, apart from
possible name-clashes, but Smalltalk-ish class methods are
more powerful than that (overridable in derived classes, &c).


> Pep 245 is missing several things that I suspect are needed.

PEP 246 seems to provide them.

> Use those two interfaces on a CountryGeneralStore object,
> and you might not get what you're looking for.

Right, so you query the object for protocol-adaptation to
the interface you desire, and either it tells you it doesn't
support it, or supplies some object (possibly itself) where
the names have the semantics of that interface.

> Requiring them to be unique doesn't hack it - it won't handle
> adding interfaces where you don't own either the interface or
> the class (i.e. add someone else's interface to an existing class.)

...which the protocol-adaptation PEP 246 handles gracefully.


> Second, how do I instantiate an object with a particular
> interface? Calling the interface isn't sufficient - I need the
> class name also.

Of course -- what use would it be to say "give me any
object whatsoever that's a ReadableStream"?  You need
to supply more info than that.

> Likewise, calling the class is not only
> insufficient because I need the interface I want, but it will
> also break code because there is no way of telling whether
> I want an interface or access to the entire class.

First you get the relevant object (e.g. via a factory callable,
which may but need not be a class object), then you ask
it for protocol-adaptation to the interface you desire.  That
is, IF PEP 246 goes through, of course.


> In the same vein, assuming I have an existing instance of a class,
> how do I call it through an interface? Is there a dynamically
> created proxy class? If so, can I add another interface to an
> existing instance of the instantiating class?

You can (if PEP 246 passes) protocol-adapt the existing instance
to the interface you require -- it either tells you it can't support
that interface, or supplies an object meeting the interface (be it
itself, or a proxy -- you don't care: object-identity is hardly
ever the issue, object state and behavior are what you care
about).  PEP 246 also provides for "third party adaptation" of
preexisting classes and protocols (i.e., interfaces), though
_somebody_ will have to write the bridge/adapter/proxy.


> In summary, I'd love to see the feature, but only if it works
> nicely.

Me too, and it seems to me that 'works nicely' equates to
"supports PEP 246".  PEP 245 will provide a nice syntax (it
does tell you it's about syntax!) for an important special
case of protocols and adaptation thereto.  PEP 246 is the
one with the real meat, IMHO.


Alex






More information about the Python-list mailing list