[Python-Dev] type categories
Sat, 24 Aug 2002 09:30:39 -0700
>>>>> "Oren" == Oren Tirosh <email@example.com> writes:
Oren> I would like to be able to declare that I need an object
Oren> with a specific interface even if the object was written
Oren> long before and I don't want to modify an existing library
Oren> just to make it conform to my interface names.
class InterfaceWrapper(ExistingClass, AbstractInterfaceClass):
I'm not saying this is a good idea :), but I believe this problem is
already solvable in the current language. The wrapper class should
pass the test of isinstance for the interface class, but the existing
class as the first parent should implement all of the calls.
Note that most other languages that actually support proper interfaces
(i.e. Java) would have similar trouble adding an interface to a prior
existing class without modifying its definition. Python actually
provides a much simpler solution than others might, it seems to me.