How many languages features are available for OO support?

Martijn Faassen m.faassen at vet.uu.nl
Fri May 17 18:24:45 EDT 2002


Byron Hammond <byronh at bigpond.net.au> wrote:
> To what extent does Python support OO?

> I know it has [multiple] inheritance and polymorphism etc, but to what
> extent does the language accomodate this and other OO concepts?

It does multiple inheritance and polymorphism very well. Python 2.2
changed the multiple inheritance rules for new style objects and added
a nicer way to call specific superclasses, but earlier versions have
always worked fine with multiple inheritance.

> Does Python support the notion of an abstract class

As others wrote, generally this is implemented by writing something like:

class Foo:
    def abstractMethod(self):
        raise NotImplementedError

which will definitely give you the intended effect if you try to use
the method directly. Of course only during runtime, but that's Python
for you (the runtime nature of Python can be very nice). Write unit tests.

> or an interface through the use of language features?

Python interfaces are always already there, but not explicitly unless
you make them explicit by just writing a class to document them (possibly
also an abstract one as above you can mix in).

In larger frameworks the implicitness of interfaces starts to hurt. 
Zope, one of Python's largest frameworks, has grown a solution for this,
now religiously applied in Zope 3, the next generation of Zope now
under development. The notion is slowly spreading into other frameworks
now (notably Twisted).

The Interface package, unfortunately not nicely packaged yet and lacking
documentation, can be found here in Zope3 CVS (you can download a 
tarball and experiment; I hope it doesn't have too many dependencies):

http://cvs.zope.org/Zope3/lib/python/Interface/?only_with_tag=Zope-3x-branch

It deserves packaging and documentation.

[snip]

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list