How many languages features are available for OO support?

Pedro B. Gomes Costa pbeck at ciberbit.pt
Fri May 17 08:41:00 EDT 2002


Hi

> > Does Python support the notion of an abstract class or an interface
> > through the use of language features?

Here is a quote from the excelente book "Thinking in Python" from my
favourite C++/Java and now Python book writer, Bruce Eckel
(www.bruceeckel.com)

"Because Python is weakly typed, it doesn't really care about interfaces -
all it cares about is applying operations to objects (in fact, Java's
interface keyword would be wasted in Python). This means that inheritance in
Python is different from inheritance in C++ or Java, where you often inherit
simply to establish a common interface. In Python, the only reason you
inherit is to inherit an implementation - to re-use the code in the base
class."

Btw, you can download a electronic version of the book from the address
above.

Pedro Costa



----- Original Message -----
From: "Gerhard Häring" <gh_pythonlist at gmx.de>
To: <python-list at python.org>
Sent: Friday, May 17, 2002 12:40 PM
Subject: Re: How many languages features are available for OO support?


> * Byron Hammond <byronh at bigpond.net.au> [2002-05-17 11:02 +0000]:
> > 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?
>
> The language is described in the Python documentation. As you will see,
> there are no abstract or interface keywords.
>
> > Does Python support the notion of an abstract class or an interface
> > through the use of language features?
>
> No, not currently. Of course there are patters for newcomers from Java
> to fake these features. But they're of little practical use, IMO.
>
> Here's a quick shot from me:
>
> class X:
>     def __init__(self, *args, **kwargs):
>         raise NotImplementedError, "This class is abstract :-P"
>
> x = X()
>
> > I ask this because not only do I want certain design decisions to be
> > clear when reading the code, but I also want to make debugging easier
> > for myself.
>
> That's what comments and docstrings are for, like:
>
> class X:
>     """{short description here}
>     Don't use this class directly. Subclass it
>     and override the {methodname} method instead."""
>
> Gerhard
> --
> This sig powered by Python!
> Außentemperatur in München: 25.8 °C      Wind: 3.5 m/s
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>







More information about the Python-list mailing list