Are there 'Interfaces' in Python??

Titus Brown t at chabry.caltech.edu
Thu Sep 27 01:51:33 EDT 2001


In article <slrn9r4m8r.lan.tim at vegeta.ath.cx>,
Tim Hammerquist <timmy at cpan.org> wrote:
>Me parece que Titus Brown <t at chabry.caltech.edu> dijo:
>>
>> [ munch of my claim "lack of interfaces sometimes bad, ==>
>>                     "interfaces sometimes good" ]
>> 
>> I would rather regard this as neutral & a convenience for people writing
>> code that uses file-object-like-things.  It's certainly not a convenience
>> for people writing new classes that attempt to emulate the behavior of
>> already-existing objects with unclear definitions, and it sure would be
>> nice to have the option of some type checking built into the language,
>> but I understand why it's not there and appreciate the convenience.  But
>> there are downsides too...
>
>This sounds like one of the many threads in c.l.smalltalk. :)
>
>If you want to use interface-style type checking, the following might
>work for you:
>
>class MyInterface:
>    # define
>
>class MyIFClass1(MyInterface):
>    # implement
>
>class MyIFClass2(MyInterface):
>    # implement
>
>class MyIFException(Exception, MyInterface):
>    # implement and extend
>
>and use isinstance(obj, MyInterface) to see if it implements it.

Well heeeeck, I can write an inheritance based type checker any hour of
the day, but if the language libraries don't support it, then you're
half pissin' into the wind, aren't you...

>It doesn't survive someone deleting keys from the o.__dict__ attribute,
>but Python's run-time nature precluded that long ago, didn't it?

;)

--titus, who loves programming in Python but wishes that there were even MORE
	nice, simple solutions to complex problems.



More information about the Python-list mailing list