PythonLanguage doesn't have interfaces like JavaInterface''''''s. If it's for MultipleInheritance, Python already has it, but for "contract compliance" it hasn't. ---- Not built-in, but ZopeApplicationServer has an 'interfaces' module that does pretty much everything you could want. The Twisted framework for AsynchronousProgramming also has a usable implementation of interfaces as regards contract compliance. -- MoeAboulkheir ---- There is a PEP for implementing Interface Syntax in Python. It's PEP-245 at http://www.python.org/peps/pep-0245.html. It would be very nice when it's implemented, but it still can't guarantee the semantics (pre/post-conditions, and invariants) even if it's implemented. Yes, you should follow the documentation very carefully. If you are a good programmer it won't be any problem but if you are a rogue or novice programmer, what happens? ''If you're a rogue programmer, your code is going to stink anyway. If you're a novice, what are you doing bungling around with interfaces?'' I do use UnitTest''''''s extensively when programming and apply them to interfaces compliance checking as well. You know interfaces sometimes can deceive you -- it could be fictitious without semantic guarantee. With UnitTest''''''s, however, the interfaces can guarantee semantics as well. The following code will tell, (If the client implements Stack''''''Interface with List''''''Stack, she'll make a unittest module for that and name it "test_StackList". In the test, she just imports all the tests from Stack''''''Interface so that interface compliances are guaranteed. She might add some List''''''Stack-specific test cases in the same module test_StackList.) #------------------------------------------------ #Stack''''''Interface.py import unittest class Stack''''''Interface: #or put this whole class as a doc string '''Anything that implements this should pass the unittests in Stack''''''Interface with its own My''''''Impl ''' def push(self, anObject): raise NotImplementedE''''''rror def pop(self): raise NotImplementedE''''''rror def isEmpty(self): raise NotImplementedE''''''rror class _Object: #helper object representing _anything_ pass class TestStackI''''''nterface(unittest.TestCase): def setUp(self): self.stack=My''''''Impl() def testPushAndPop(self): o=_Object() self.stack.push(o) self.assertEqual(o, self.stack.pop()) def testPopOnEmpty(self): self.assert_(self.stack.isEmpty()) self.assertRaises(Index''''''Error,self.stack.pop) def testPushAllAndPopAll(self): oList=[_Object() for i in range(10)] for each in oList: self.stack.push(each) oList.reverse() for each in oList: self.assertEqual(each, self.stack.pop()) My''''''Impl=Stack''''''Interface #please override this with the real implementation if __name__=='__main__': # you won't run this module directly though unittest.main() #------------------------------------------------ #List''''''Stack.py from Stack''''''Interface import Stack''''''Interface class List''''''Stack(Stack''''''Interface): def __init__(self): self._s=[] def push(self, anObject): self._s.append(anObject) def pop(self): return self._s.pop() def isEmpty(self): return len(self._s)==0 #------------------------------------------------ #test_ListStack.py import unittest import Stack''''''Interface from List''''''Stack import List''''''Stack Stack''''''Interface.My''''''Impl=List''''''Stack from Stack''''''Interface import * #if you want to implement several #interfaces just import all of them here if __name__=='__main__': unittest.main() -- JuneKim ---- CategoryInterface CategoryPython