is python Object oriented??

Chris Rebert clp2 at rebertia.com
Fri Jan 30 01:15:59 EST 2009


On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo <hungvn94 at gmail.com> wrote:
<snip>
> I'm new to Python and also wondering about OOP in Python.
>
> I want to justify the above question (is Python Object-Oriented?).
> Does Python follow the concepts/practices of Encapsulation,
> Polymorphism and Interface, which are quite familiar to Java
> programmers?

If you're looking for a benchmark for object-orientedness, Smalltalk,
not Java, is the canonical language to compare against.

Anyway, to your three-pronged question:
- Yes, Python supports polymorphism. I find it hard to think of an
example of an OO language that doesn't.

- Python does not support interfaces in the Java sense (although there
are a few third-party libraries that add such support); neither does
Smalltalk. Instead, both Smalltalk and Python use duck-typing to
similar effect. See http://en.wikipedia.org/wiki/Duck_typing

- Python supports encapsulation. Prefixing an attribute/method with an
underscore indicates that other programmers should treat it as
'private'. However, unlike B&D languages, Python itself does nothing
to enforce this privacy, leaving it instead to the good judgement of
the programmer, under the philosophy that "We're all consenting adults
here". This allows people to meddle with internals, at their own risk,
if it ends up being absolutely necessary. The enforcement point is
largely academic anyway, as most languages' reflection APIs let you
poke at ostensibly "private" things.

Cheers,
Chris

P.S. You appear to have posted the same message 3 times(!), which is a
bit annoying for readers.

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list