Interfaces (a la PEP 245 and Zope)

Brendan Hahn bhahn at spam-spam.g0-away.com
Fri Aug 1 16:04:17 EDT 2003


Heiko Wundram <heikowu at ceosg.de> wrote:
>Simplest way I use to implement "interfaces":
>
>class IEditor(object):
>        def getSelection(self,start,end):
>                raise NotImplementedError("Implement this for IEditor")
   etc...

How about an Interface metaclass that replaces any class methods with an
appropriate exception-raiser.  It would save a little typing, e.g.

   class IEditor():
      __metaclass__ = Interface
      def GetSelection(self, start, end): pass
      def SetSelection(self, start, end, data): pass

...and so on.

-- 
brendan DOT hahn AT hp DOT com




More information about the Python-list mailing list