Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Encapsulation, inheritance and polymorphism

Reply
Thread Tools

Re: Encapsulation, inheritance and polymorphism

 
 
Devin Jeanpierre
Guest
Posts: n/a
 
      07-17-2012
On Tue, Jul 17, 2012 at 4:45 AM, Lipska the Kat <> wrote:
> Is Python truly OO or is it just one way to use the language. I see some
> documentation relating to classes but nothing on instantiation .. in fact
> the documentation appears to say that classes are used in a static way e.g
> ClassName.method(), and command line scripting is really outside the scope
> of other OO languages I have experienced.


It doesn't look like you're reading the section on classes:

http://docs.python.org/tutorial/classes.html

You create a class like this:

class MyClass(MySuperclass1, MySuperclass2):
# class attributes and methods
attr = 3
def method(self): print self.attr

You can instantiate it by calling the class, as if it were a function:

myinstance = MyClass()

You call a method getting the method (myinstance.method), and then
calling that as if it were a function.

myinstance.method()

Polymorphism is "duck typed" -- that is, it's based on the
presence/absence of attributes and methods, not on declared interfaces
(Python has no interfaces). So, for example, "foo.read()" works on any
object bound to the name "foo", as long as it has a read method that
takes no parameters. This could be a file-like object, but it could
also be something completely different that just happens to have a
method by the same name.

> Is there a previous discussion in the group that I could read.


Man, I dunno, the list archives are impossible to navigate.

-- Devin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Class Variables, Inheritance, and Polymorphism crjjrc C++ 8 04-05-2007 08:39 PM
Dynamic polymorphism vs. Static polymorphism Krivenok Dmitry C++ 13 06-01-2006 09:49 AM
I need help with "Inheritance" and "Polymorphism" Fao C++ 13 05-01-2006 11:55 PM
Inheritance, polymorphism, and introspection in Python combinational.logic $ soc-ip.com Python 0 05-27-2005 05:36 PM
trying to understand Inheritance, Polymorphism and templates sapropel C++ 1 05-14-2004 02:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57