Yet Another PEP: Interface Adapter Mechanism __adapt__

Alex Shindich alex at server01.shindich.com
Mon Mar 26 01:33:14 EST 2001


On Sun, 25 Mar 2001, Clark C. Evans wrote:

> On Mon, 26 Mar 2001, Alex Shindich wrote:
> > It sounds like your PEP suggests adding Strategy pattern
> > behavior to all Python objects.
> 
> I'm suggesting a bi-directional adapter pattern.  IMHO,
> It has nothing to do with the strategy pattern.   Did you
> read the proposal?
I have to confess... I only read the beginning... OK! Shoot me in the head
now!
>Evidently my explanation failed, hunh?
Let's see... The abstract section of the PEP says: "This proposal allows 
a standard and extensible method to ask two types of questions:  Is a
particular object compliant with a given protocol?" The following
describes the strategy pattern: "The Strategy pattern provides a means of
parameterizing a component to accept an algorithm.  This keeps the
component simpler, and lets clients pick and choose an algorithm
specifically tailored to their needs." See any similarities?
> 
> > Another way of looking at your PEP is to say that you are 
> > asking for Python Java-like interfaces.
> 
> No, actually there are other PEPs that do that.
> 
That is true, there is PEP-245. But in some sense, an ability to determine
"is-a" relationship is no different from asking "do you support
protocol Blah?" 

Other comments:
1. You are making an assumption that each class will provide adaptors to
some set of protocols, thus entangling the class and available set of
protocol conversions. Why can't protocol conversion live outside of the
class?
2. Is adaption symmetric? If class A provides an adaptor for class B,
mustn't class B provide an adaptor for class A?
 
3. Versioning is not mentioned anywhere in your PEP. Once a class defines
an adaptor for a protocol, the protocol better not change. Otherwise every
adaptor needs to change to match the new definition of the
protocol. 
 
That's all I have got so far... I'll send you more once I read more of the
PEP. ;))

-- 
Alex Shindich
mailto:alex at shindich.com
Visit http://www.shindich.com/





More information about the Python-list mailing list