>>Yup, I was thinking more in terms of the Java idea, whereby an >>interface is declared specifically and then a class claiming >>to implement it causes compilation problems if it doesn't >>properly implement it.
I guessed as much but that is an idea dreamt up by Microsoft for COM and picked up by Java to compensate for its lack of multiple inheritance. Since Python supports MI interfaces are neither useful nor desirable IMHO! Howeber they are being introduced in a future version I believe, mainly to appease the legions of Java programmers who think they are using OOP... >>> class InterfaceError(Exception): pass >>> >>> class Interface(Abstract): >>> def myMethod(self): pass >>> def myOther(self): raise InterfaceErrror >>> >>> Does that do what you want? >> >>I presume the "def myMethod(self): pass" is >> just for an 'optional' part of the interface? Its an optional way of doing interfaces. If you take the ObjectiveC or lisp approach defining a null method is a valid implementation, the second case shows what to do if you want a failure for unimplemented methods. The 'pass' approach is most akin to mixin style programming used in Lisp to implement interfaces (as originally defined in the Flavors dialect of Lisp) and used in most Multiple Inheriting languages(including C++) where as the exception style is typically used in statically typed single inheritance languages. Python can use the somple method of throwing an exception when a method is not found - this allows partial implementation of interfaces as is commonly found with "file-like2 interfaces where only open() and read() are actually coded not the whole gamut of file object methods. This is a much more powerful mechanism since it reduces the code to be produced while still ensuring errors are thrown when actually necessary. >>wondering if there was any other common ways >> to make interfaces more Not that I know of, after all one of the strengths of Python (and other dynamic OOPLs) is that they on rely on static checking of types. >>here to reply to the email address of the sender of the message In general yes, use Reply-All. It seems to prevent problems. Alan G. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor