On Fri, Jan 30, 2009 at 5:15 PM, Chris Rebert <c...@rebertia.com> wrote:
> On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo <hungv...@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. I was introduced to OOP via C++/Java, so its quite nature to compare and contrast with the languages you know even they seem not to be original. I definitely will learn about Smalltalk. > > 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 Its seem to me that duck typing is a special case of static vs dynamic type debate and clearly Python is a dynamic type philoshopy's follower. > > - 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. I like the flexibility of not being enforced to the encapsulation rules, however, you're right, we do at our own risk and have to tradeoff the flexibility with the secure a static type system like Java provides. P.S. You appear to have posted the same message 3 times(!), which is a > bit annoying for readers. sorry for this annoyance. I dont know why a new post was made whenever i cliked on the topic link. Probably, there's something wrong with google group. on investigating... > > -- > Follow the path of the Iguana... > http://rebertia.com >
-- http://mail.python.org/mailman/listinfo/python-list