[Tutor] interfaces and abstract classes in python
alan.gauld at freenet.co.uk
Sun Nov 6 16:19:48 CET 2005
> Interfaces and abstract classes - I know they don't exist per se in
First you need to define what you mean by the terms.
Every class has an interface - it is the set of messages to which
An Abstract class is one which is not intended to be instantiated.
class AbstractClassError(Exception): pass
def __init__(self): raise AbstractClassError
> But what are the closest analogues? I've found a few examples,
Assuming you mean Interface in the Microsoft/Java specific sense
of the term rather than the simple OOP sense, then an Interface
class is simply an abstract class with empty methods.
class InterfaceError(Exception): pass
def myMethod(self): pass
def myOther(self): raise InterfaceErrror
Does that do what you want?
Author of the learn to program web tutor
More information about the Tutor